|
SDL 3.0
|
#include <SDL3/SDL_stdinc.h>#include <SDL3/SDL_error.h>#include <SDL3/SDL_iostream.h>#include <SDL3/SDL_properties.h>#include <SDL3/SDL_begin_code.h>#include <SDL3/SDL_close_code.h>Go to the source code of this file.
Macros | |
| #define | SDL_PROP_PROCESS_CREATE_ARGS_POINTER "SDL.process.create.args" |
| #define | SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER "SDL.process.create.environment" |
| #define | SDL_PROP_PROCESS_CREATE_WORKING_DIRECTORY_STRING "SDL.process.create.working_directory" |
| #define | SDL_PROP_PROCESS_CREATE_STDIN_NUMBER "SDL.process.create.stdin_option" |
| #define | SDL_PROP_PROCESS_CREATE_STDIN_POINTER "SDL.process.create.stdin_source" |
| #define | SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER "SDL.process.create.stdout_option" |
| #define | SDL_PROP_PROCESS_CREATE_STDOUT_POINTER "SDL.process.create.stdout_source" |
| #define | SDL_PROP_PROCESS_CREATE_STDERR_NUMBER "SDL.process.create.stderr_option" |
| #define | SDL_PROP_PROCESS_CREATE_STDERR_POINTER "SDL.process.create.stderr_source" |
| #define | SDL_PROP_PROCESS_CREATE_STDERR_TO_STDOUT_BOOLEAN "SDL.process.create.stderr_to_stdout" |
| #define | SDL_PROP_PROCESS_CREATE_BACKGROUND_BOOLEAN "SDL.process.create.background" |
| #define | SDL_PROP_PROCESS_CREATE_CMDLINE_STRING "SDL.process.create.cmdline" |
| #define | SDL_PROP_PROCESS_PID_NUMBER "SDL.process.pid" |
| #define | SDL_PROP_PROCESS_STDIN_POINTER "SDL.process.stdin" |
| #define | SDL_PROP_PROCESS_STDOUT_POINTER "SDL.process.stdout" |
| #define | SDL_PROP_PROCESS_STDERR_POINTER "SDL.process.stderr" |
| #define | SDL_PROP_PROCESS_BACKGROUND_BOOLEAN "SDL.process.background" |
Typedefs | |
| typedef struct SDL_Process | SDL_Process |
Enumerations | |
| enum | SDL_ProcessIO { SDL_PROCESS_STDIO_INHERITED , SDL_PROCESS_STDIO_NULL , SDL_PROCESS_STDIO_APP , SDL_PROCESS_STDIO_REDIRECT } |
Functions | |
| SDL_Process * | SDL_CreateProcess (const char *const *args, bool pipe_stdio) |
| SDL_Process * | SDL_CreateProcessWithProperties (SDL_PropertiesID props) |
| SDL_PropertiesID | SDL_GetProcessProperties (SDL_Process *process) |
| void * | SDL_ReadProcess (SDL_Process *process, size_t *datasize, int *exitcode) |
| SDL_IOStream * | SDL_GetProcessInput (SDL_Process *process) |
| SDL_IOStream * | SDL_GetProcessOutput (SDL_Process *process) |
| bool | SDL_KillProcess (SDL_Process *process, bool force) |
| bool | SDL_WaitProcess (SDL_Process *process, bool block, int *exitcode) |
| void | SDL_DestroyProcess (SDL_Process *process) |
| #define SDL_PROP_PROCESS_BACKGROUND_BOOLEAN "SDL.process.background" |
Definition at line 277 of file SDL_process.h.
| #define SDL_PROP_PROCESS_CREATE_ARGS_POINTER "SDL.process.create.args" |
Definition at line 229 of file SDL_process.h.
| #define SDL_PROP_PROCESS_CREATE_BACKGROUND_BOOLEAN "SDL.process.create.background" |
Definition at line 239 of file SDL_process.h.
| #define SDL_PROP_PROCESS_CREATE_CMDLINE_STRING "SDL.process.create.cmdline" |
Definition at line 240 of file SDL_process.h.
| #define SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER "SDL.process.create.environment" |
Definition at line 230 of file SDL_process.h.
| #define SDL_PROP_PROCESS_CREATE_STDERR_NUMBER "SDL.process.create.stderr_option" |
Definition at line 236 of file SDL_process.h.
| #define SDL_PROP_PROCESS_CREATE_STDERR_POINTER "SDL.process.create.stderr_source" |
Definition at line 237 of file SDL_process.h.
| #define SDL_PROP_PROCESS_CREATE_STDERR_TO_STDOUT_BOOLEAN "SDL.process.create.stderr_to_stdout" |
Definition at line 238 of file SDL_process.h.
| #define SDL_PROP_PROCESS_CREATE_STDIN_NUMBER "SDL.process.create.stdin_option" |
Definition at line 232 of file SDL_process.h.
| #define SDL_PROP_PROCESS_CREATE_STDIN_POINTER "SDL.process.create.stdin_source" |
Definition at line 233 of file SDL_process.h.
| #define SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER "SDL.process.create.stdout_option" |
Definition at line 234 of file SDL_process.h.
| #define SDL_PROP_PROCESS_CREATE_STDOUT_POINTER "SDL.process.create.stdout_source" |
Definition at line 235 of file SDL_process.h.
| #define SDL_PROP_PROCESS_CREATE_WORKING_DIRECTORY_STRING "SDL.process.create.working_directory" |
Definition at line 231 of file SDL_process.h.
| #define SDL_PROP_PROCESS_PID_NUMBER "SDL.process.pid" |
Definition at line 273 of file SDL_process.h.
| #define SDL_PROP_PROCESS_STDERR_POINTER "SDL.process.stderr" |
Definition at line 276 of file SDL_process.h.
| #define SDL_PROP_PROCESS_STDIN_POINTER "SDL.process.stdin" |
Definition at line 274 of file SDL_process.h.
| #define SDL_PROP_PROCESS_STDOUT_POINTER "SDL.process.stdout" |
Definition at line 275 of file SDL_process.h.
| typedef struct SDL_Process SDL_Process |
Process control support.
These functions provide a cross-platform way to spawn and manage OS-level processes.
You can create a new subprocess with SDL_CreateProcess() and optionally read and write to it using SDL_ReadProcess() or SDL_GetProcessInput() and SDL_GetProcessOutput(). If more advanced functionality like chaining input between processes is necessary, you can use SDL_CreateProcessWithProperties().
You can get the status of a created process with SDL_WaitProcess(), or terminate the process with SDL_KillProcess().
Don't forget to call SDL_DestroyProcess() to clean up, whether the process process was killed, terminated on its own, or is still running! An opaque handle representing a system process.
Definition at line 64 of file SDL_process.h.
| enum SDL_ProcessIO |
Description of where standard I/O should be directed when creating a process.
If a standard I/O stream is set to SDL_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_NULL, 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 SDL_PROCESS_STDIO_APP, it is connected to a new SDL_IOStream that is available to the application. Standard input will be available as SDL_PROP_PROCESS_STDIN_POINTER and allows SDL_GetProcessInput(), standard output will be available as SDL_PROP_PROCESS_STDOUT_POINTER and allows SDL_ReadProcess() and SDL_GetProcessOutput(), and standard error will be available as SDL_PROP_PROCESS_STDERR_POINTER in the properties for the created process.
If a standard I/O stream is set to SDL_PROCESS_STDIO_REDIRECT, it is connected to an existing SDL_IOStream provided by the application. Standard input is provided using SDL_PROP_PROCESS_CREATE_STDIN_POINTER, standard output is provided using SDL_PROP_PROCESS_CREATE_STDOUT_POINTER, and standard error is provided using SDL_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 SDL_IOStream with SDL_PROCESS_STDIO_REDIRECT, it must have SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER or SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER set. This is true for streams representing files and process I/O.
| Enumerator | |
|---|---|
| SDL_PROCESS_STDIO_INHERITED | The I/O stream is inherited from the application. |
| SDL_PROCESS_STDIO_NULL | The I/O stream is ignored. |
| SDL_PROCESS_STDIO_APP | The I/O stream is connected to a new SDL_IOStream that the application can read or write |
| SDL_PROCESS_STDIO_REDIRECT | The I/O stream is redirected to an existing SDL_IOStream. |
Definition at line 150 of file SDL_process.h.
|
extern |
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 NULL, e.g.:
Setting pipe_stdio to true is equivalent to setting SDL_PROP_PROCESS_CREATE_STDIN_NUMBER and SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER to SDL_PROCESS_STDIO_APP, and will allow the use of SDL_ReadProcess() or SDL_GetProcessInput() and SDL_GetProcessOutput().
See SDL_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. |
\threadsafety It is safe to call this function from any thread.
|
extern |
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 SDL_WaitProcess() instead.
| props | the properties to use. |
\threadsafety It is safe to call this function from any thread.
|
extern |
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 SDL_KillProcess().
| process | The process object to destroy. |
\threadsafety This function is not thread safe.
|
extern |
Get the SDL_IOStream associated with process standard input.
The process must have been created with SDL_CreateProcess() and pipe_stdio set to true, or with SDL_CreateProcessWithProperties() and SDL_PROP_PROCESS_CREATE_STDIN_NUMBER set to SDL_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 SDL_GetProcessOutput() and read the output in parallel with writing input.
| process | The process to get the input stream for. |
\threadsafety It is safe to call this function from any thread.
|
extern |
Get the SDL_IOStream associated with process standard output.
The process must have been created with SDL_CreateProcess() and pipe_stdio set to true, or with SDL_CreateProcessWithProperties() and SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER set to SDL_PROCESS_STDIO_APP.
Reading from this stream can return 0 with SDL_GetIOStatus() returning SDL_IO_STATUS_NOT_READY if no output is available yet.
| process | The process to get the output stream for. |
\threadsafety It is safe to call this function from any thread.
|
extern |
Get the properties associated with a process.
The following read-only properties are provided by SDL:
| process | the process to query. |
\threadsafety It is safe to call this function from any thread.
|
extern |
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. |
\threadsafety This function is not thread safe.
|
extern |
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 SDL_free().
| process | The process to read. |
| datasize | a pointer filled in with the number of bytes read, may be NULL. |
| exitcode | a pointer filled in with the process exit code if the process has exited, may be NULL. |
\threadsafety This function is not thread safe.
|
extern |
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 SDL_WaitProcess(). If you don't do this the process might be blocked indefinitely waiting for output to be read and SDL_WaitProcess() 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 NULL. |
\threadsafety This function is not thread safe.