|
SDL3pp
A slim C++ wrapper for SDL3
|
Process control support. More...
Namespaces | |
| namespace | SDL::prop |
| Constants for Properties keys. | |
| namespace | SDL::prop::Process |
| Properties for processes. | |
| namespace | SDL::prop::Process::Create |
| Properties for process creation. | |
Classes | |
| struct | SDL::Process |
| An opaque handle representing a system process. More... | |
Typedefs | |
| using | SDL::ProcessRaw = SDL_Process* |
| Alias to raw representation for Process. | |
| using | SDL::ProcessRef = ResourceRef<Process> |
| Reference for Process. | |
| using | SDL::ProcessIO = SDL_ProcessIO |
| Description of where standard I/O should be directed when creating a process. | |
Functions | |
| Process | SDL::CreateProcess (const char *const *args, bool pipe_stdio) |
| Create a new process. | |
| Process | SDL::CreateProcessWithProperties (PropertiesRef props) |
| Create a new process with the specified properties. | |
| PropertiesRef | SDL::GetProcessProperties (ProcessRef process) |
| Get the properties associated with a process. | |
| StringResult | SDL::ReadProcess (ProcessRef process, int *exitcode=nullptr) |
| Read all the output from a process. | |
| IOStreamRef | SDL::GetProcessInput (ProcessRef process) |
| Get the IOStream associated with process standard input. | |
| IOStreamRef | SDL::GetProcessOutput (ProcessRef process) |
| Get the IOStream associated with process standard output. | |
| void | SDL::KillProcess (ProcessRef process, bool force) |
| Stop a process. | |
| bool | SDL::WaitProcess (ProcessRef process, bool block, int *exitcode) |
| Wait for a process to finish. | |
| void | SDL::DestroyProcess (ProcessRaw process) |
| Destroy a previously created process object. | |
| SDL::Process::Process (const char *const *args, bool pipe_stdio) | |
| Create a new process. | |
| SDL::Process::Process (PropertiesRef props) | |
| Create a new process with the specified properties. | |
| PropertiesRef | SDL::Process::GetProperties () const |
| Get the properties associated with a process. | |
| StringResult | SDL::Process::Read (int *exitcode=nullptr) |
| Read all the output from a process. | |
| IOStreamRef | SDL::Process::GetInput () |
| Get the IOStream associated with process standard input. | |
| IOStreamRef | SDL::Process::GetOutput () |
| Get the IOStream associated with process standard output. | |
| void | SDL::Process::Kill (bool force) |
| Stop a process. | |
| bool | SDL::Process::Wait (bool block, int *exitcode) |
| Wait for a process to finish. | |
| void | SDL::Process::Destroy () |
| Destroy a previously created process object. | |
Variables | |
| constexpr ProcessIO | SDL::PROCESS_STDIO_INHERITED |
| The I/O stream is inherited from the application. | |
| constexpr ProcessIO | SDL::PROCESS_STDIO_NULL |
| The I/O stream is ignored. | |
| constexpr ProcessIO | SDL::PROCESS_STDIO_APP = SDL_PROCESS_STDIO_APP |
| The I/O stream is connected to a new IOStream that the application can read or write. | |
| constexpr ProcessIO | SDL::PROCESS_STDIO_REDIRECT = SDL_PROCESS_STDIO_REDIRECT |
| The I/O stream is redirected to an existing IOStream. | |
Process control support.
These functions provide a cross-platform way to spawn and manage OS-level processes.
You can create a new subprocess with CreateProcess() and optionally read and write to it using Process.Read() or Process.GetInput() and Process.GetOutput(). If more advanced functionality like chaining input between processes is necessary, you can use CreateProcessWithProperties().
You can get the status of a created process with Process.Wait(), or terminate the process with Process.Kill().
Don't forget to call Process.Destroy() to clean up, whether the process process was killed, terminated on its own, or is still running!
| using SDL::ProcessIO = SDL_ProcessIO |
Description of where standard I/O should be directed when creating a process.
If a standard I/O stream is set to PROCESS_STDIO_INHERITED, it will go to the same place as the application's I/O stream. This is the default for standard output and standard error.
If a standard I/O stream is set to SDL_PROCESS_STDIO_nullptr, it is connected to NUL: on Windows and /dev/null on POSIX systems. This is the default for standard input.
If a standard I/O stream is set to PROCESS_STDIO_APP, it is connected to a new IOStream that is available to the application. Standard input will be available as prop.Process.STDIN_POINTER and allows Process.GetInput(), standard output will be available as prop.Process.STDOUT_POINTER and allows Process.Read() and Process.GetOutput(), and standard error will be available as prop.Process.STDERR_POINTER in the properties for the created process.
If a standard I/O stream is set to PROCESS_STDIO_REDIRECT, it is connected to an existing IOStream provided by the application. Standard input is provided using prop.Process.Create.STDIN_POINTER, standard output is provided using prop.Process.Create.STDOUT_POINTER, and standard error is provided using prop.Process.Create.STDERR_POINTER in the creation properties. These existing streams should be closed by the application once the new process is created.
In order to use an IOStream with PROCESS_STDIO_REDIRECT, it must have prop.IOStream.WINDOWS_HANDLE_POINTER or prop.IOStream.FILE_DESCRIPTOR_NUMBER set. This is true for streams representing files and process I/O.
| using SDL::ProcessRef = ResourceRef<Process> |
Reference for Process.
This does not take ownership!
|
inline |
Create a new process.
The path to the executable is supplied in args[0]. args[1..N] are additional arguments passed on the command line of the new process, and the argument list should be terminated with a nullptr, e.g.:
Setting pipe_stdio to true is equivalent to setting prop.Process.Create.STDIN_NUMBER and prop.Process.Create.STDOUT_NUMBER to PROCESS_STDIO_APP, and will allow the use of Process.Read() or Process.GetInput() and Process.GetOutput().
See CreateProcessWithProperties() for more details.
| args | the path and arguments for the new process. |
| pipe_stdio | true to create pipes to the process's standard input and from the process's standard output, false for the process to have no input and inherit the application's standard output. |
|
inline |
Create a new process with the specified properties.
These are the supported properties:
On POSIX platforms, wait() and waitpid(-1, ...) should not be called, and SIGCHLD should not be ignored or handled because those would prevent SDL from properly tracking the lifetime of the underlying process. You should use Process.Wait() instead.
| props | the properties to use. |
|
inline |
Destroy a previously created process object.
Note that this does not stop the process, just destroys the SDL object used to track it. If you want to stop the process you should use Process.Kill().
|
inline |
Destroy a previously created process object.
Note that this does not stop the process, just destroys the SDL object used to track it. If you want to stop the process you should use Process.Kill().
| process | The process object to destroy. |
|
inline |
Get the IOStream associated with process standard input.
The process must have been created with CreateProcess() and pipe_stdio set to true, or with CreateProcessWithProperties() and prop.Process.Create.STDIN_NUMBER set to PROCESS_STDIO_APP.
Writing to this stream can return less data than expected if the process hasn't read its input. It may be blocked waiting for its output to be read, if so you may need to call Process.GetOutput() and read the output in parallel with writing input.
|
inline |
Get the IOStream associated with process standard output.
The process must have been created with CreateProcess() and pipe_stdio set to true, or with CreateProcessWithProperties() and prop.Process.Create.STDOUT_NUMBER set to PROCESS_STDIO_APP.
Reading from this stream can return 0 with IOStream.GetStatus() returning IO_STATUS_NOT_READY if no output is available yet.
|
inline |
Get the IOStream associated with process standard input.
The process must have been created with CreateProcess() and pipe_stdio set to true, or with CreateProcessWithProperties() and prop.Process.Create.STDIN_NUMBER set to PROCESS_STDIO_APP.
Writing to this stream can return less data than expected if the process hasn't read its input. It may be blocked waiting for its output to be read, if so you may need to call Process.GetOutput() and read the output in parallel with writing input.
| process | The process to get the input stream for. |
|
inline |
Get the IOStream associated with process standard output.
The process must have been created with CreateProcess() and pipe_stdio set to true, or with CreateProcessWithProperties() and prop.Process.Create.STDOUT_NUMBER set to PROCESS_STDIO_APP.
Reading from this stream can return 0 with IOStream.GetStatus() returning IO_STATUS_NOT_READY if no output is available yet.
| process | The process to get the output stream for. |
|
inline |
Get the properties associated with a process.
The following read-only properties are provided by SDL:
| process | the process to query. |
| Error | on failure. |
|
inline |
Get the properties associated with a process.
The following read-only properties are provided by SDL:
| Error | on failure. |
|
inline |
Stop a process.
| force | true to terminate the process immediately, false to try to stop the process gracefully. In general you should try to stop the process gracefully first as terminating a process may leave it with half-written data or in some other unstable state. |
| Error | on failure. |
|
inline |
Stop a process.
| process | The process to stop. |
| force | true to terminate the process immediately, false to try to stop the process gracefully. In general you should try to stop the process gracefully first as terminating a process may leave it with half-written data or in some other unstable state. |
| Error | on failure. |
|
inline |
Create a new process.
The path to the executable is supplied in args[0]. args[1..N] are additional arguments passed on the command line of the new process, and the argument list should be terminated with a nullptr, e.g.:
Setting pipe_stdio to true is equivalent to setting prop.Process.Create.STDIN_NUMBER and prop.Process.Create.STDOUT_NUMBER to PROCESS_STDIO_APP, and will allow the use of Process.Read() or Process.GetInput() and Process.GetOutput().
See CreateProcessWithProperties() for more details.
| args | the path and arguments for the new process. |
| pipe_stdio | true to create pipes to the process's standard input and from the process's standard output, false for the process to have no input and inherit the application's standard output. |
|
inline |
Create a new process with the specified properties.
These are the supported properties:
On POSIX platforms, wait() and waitpid(-1, ...) should not be called, and SIGCHLD should not be ignored or handled because those would prevent SDL from properly tracking the lifetime of the underlying process. You should use Process.Wait() instead.
| props | the properties to use. |
|
inline |
Read all the output from a process.
If a process was created with I/O enabled, you can use this function to read the output. This function blocks until the process is complete, capturing all output, and providing the process exit code.
The data is allocated with a zero byte at the end (null terminated) for convenience. This extra byte is not included in the value reported via datasize.
The data should be freed with free().
| exitcode | a pointer filled in with the process exit code if the process has exited, may be nullptr. |
|
inline |
Read all the output from a process.
If a process was created with I/O enabled, you can use this function to read the output. This function blocks until the process is complete, capturing all output, and providing the process exit code.
The data is allocated with a zero byte at the end (null terminated) for convenience. This extra byte is not included in the value reported via datasize.
The data should be freed with free().
| process | The process to read. |
| exitcode | a pointer filled in with the process exit code if the process has exited, may be nullptr. |
|
inline |
Wait for a process to finish.
This can be called multiple times to get the status of a process.
The exit code will be the exit code of the process if it terminates normally, a negative signal if it terminated due to a signal, or -255 otherwise. It will not be changed if the process is still running.
If you create a process with standard output piped to the application (pipe_stdio being true) then you should read all of the process output before calling Process.Wait(). If you don't do this the process might be blocked indefinitely waiting for output to be read and Process.Wait() will never return true;
| block | If true, block until the process finishes; otherwise, report on the process' status. |
| exitcode | a pointer filled in with the process exit code if the process has exited, may be nullptr. |
|
inline |
Wait for a process to finish.
This can be called multiple times to get the status of a process.
The exit code will be the exit code of the process if it terminates normally, a negative signal if it terminated due to a signal, or -255 otherwise. It will not be changed if the process is still running.
If you create a process with standard output piped to the application (pipe_stdio being true) then you should read all of the process output before calling Process.Wait(). If you don't do this the process might be blocked indefinitely waiting for output to be read and Process.Wait() will never return true;
| process | The process to wait for. |
| block | If true, block until the process finishes; otherwise, report on the process' status. |
| exitcode | a pointer filled in with the process exit code if the process has exited, may be nullptr. |
|
constexpr |
The I/O stream is inherited from the application.
|
constexpr |
The I/O stream is ignored.