sdl3-bindgen-sys
Safe HaskellNone
LanguageGHC2021

SDL3.Sys.Process

Description

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 readProcess or getProcessInput and getProcessOutput. 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 waitProcess, or terminate the process with killProcess.

Don't forget to call 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.

See also
createProcess

FFI conventions

Unsuffixed aliases are unsafe foreign imports; aliases suffixed Safe are safe. Functions whose callbacks fire during the call export only the Safe alias (the genuine unsafe import stays reachable under SDL3.Sys.Bindgen.Process.Unsafe); functions curated unsafe-only export only the unsuffixed one. Each alias's documentation records its flavor and rationale.

Full conventions: SDL3.Sys.

Since: 3.2.0

Synopsis

Documentation

Function aliases

createProcess Source #

Arguments

:: PtrConst (PtrConst CChar)
args
the path and arguments for the new process.
-> Bool
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.
-> IO (Ptr SDL_Process) 

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.:

    const char *args[] = { "myprogram", "argument", NULL };
    

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 readProcess or getProcessInput and getProcessOutput.

See createProcessWithProperties for more details.

Returns
the newly created and running process, or NULL if the process couldn't be created.
Thread safety
It is safe to call this function from any thread.
See also
createProcessWithProperties, getProcessProperties, readProcess, getProcessInput, getProcessOutput, killProcess, waitProcess, destroyProcess

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_CreateProcess. The safe flavor is createProcessSafe .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_CreateProcess, defined at SDL3/SDL_process.h 106:43

Since: 3.2.0

createProcessSafe Source #

Arguments

:: PtrConst (PtrConst CChar)
args
the path and arguments for the new process.
-> Bool
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.
-> IO (Ptr SDL_Process) 

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.:

    const char *args[] = { "myprogram", "argument", NULL };
    

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 readProcess or getProcessInput and getProcessOutput.

See createProcessWithProperties for more details.

Returns
the newly created and running process, or NULL if the process couldn't be created.
Thread safety
It is safe to call this function from any thread.
See also
createProcessWithProperties, getProcessProperties, readProcess, getProcessInput, getProcessOutput, killProcess, waitProcess, destroyProcess

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_CreateProcess. The unsafe flavor is createProcess .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_CreateProcess, defined at SDL3/SDL_process.h 106:43

Since: 3.2.0

createProcessWithProperties Source #

Arguments

:: SDL_PropertiesID
props
the properties to use.
-> IO (Ptr SDL_Process) 

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 waitProcess instead.

Returns
the newly created and running process, or NULL if the process couldn't be created.
Thread safety
It is safe to call this function from any thread.
See also
createProcess, getProcessProperties, readProcess, getProcessInput, getProcessOutput, killProcess, waitProcess, destroyProcess

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_CreateProcessWithProperties. The safe flavor is createProcessWithPropertiesSafe .
C declaration
SDL_CreateProcessWithProperties, defined at SDL3/SDL_process.h 227:43

Since: 3.2.0

createProcessWithPropertiesSafe Source #

Arguments

:: SDL_PropertiesID
props
the properties to use.
-> IO (Ptr SDL_Process) 

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 waitProcess instead.

Returns
the newly created and running process, or NULL if the process couldn't be created.
Thread safety
It is safe to call this function from any thread.
See also
createProcess, getProcessProperties, readProcess, getProcessInput, getProcessOutput, killProcess, waitProcess, destroyProcess

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_CreateProcessWithProperties. The unsafe flavor is createProcessWithProperties .
C declaration
SDL_CreateProcessWithProperties, defined at SDL3/SDL_process.h 227:43

Since: 3.2.0

getProcessProperties Source #

Arguments

:: Ptr SDL_Process
process
the process to query.
-> IO SDL_PropertiesID 

Get the properties associated with a process.

The following read-only properties are provided by SDL:

Returns
a valid property ID on success or 0 on failure; call getError for more information.
Thread safety
It is safe to call this function from any thread.
See also
createProcess, createProcessWithProperties

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_GetProcessProperties. The safe flavor is getProcessPropertiesSafe .
C declaration
SDL_GetProcessProperties, defined at SDL3/SDL_process.h 271:46

Since: 3.2.0

getProcessPropertiesSafe Source #

Arguments

:: Ptr SDL_Process
process
the process to query.
-> IO SDL_PropertiesID 

Get the properties associated with a process.

The following read-only properties are provided by SDL:

Returns
a valid property ID on success or 0 on failure; call getError for more information.
Thread safety
It is safe to call this function from any thread.
See also
createProcess, createProcessWithProperties

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_GetProcessProperties. The unsafe flavor is getProcessProperties .
C declaration
SDL_GetProcessProperties, defined at SDL3/SDL_process.h 271:46

Since: 3.2.0

readProcess Source #

Arguments

:: Ptr SDL_Process
process
The process to read.
-> Ptr CSize
datasize
a pointer filled in with the number of bytes read, may be NULL.
-> Ptr CInt
exitcode
a pointer filled in with the process exit code if the process has exited, may be NULL.
-> IO (Ptr Void) 

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.

Returns
the data or NULL on failure; call getError for more information.
Thread safety
This function is not thread safe.
See also
createProcess, createProcessWithProperties, destroyProcess

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_ReadProcess. The safe flavor is readProcessSafe : blocks until the process closes its output.
C declaration
SDL_ReadProcess, defined at SDL3/SDL_process.h 308:36

Since: 3.2.0

readProcessSafe Source #

Arguments

:: Ptr SDL_Process
process
The process to read.
-> Ptr CSize
datasize
a pointer filled in with the number of bytes read, may be NULL.
-> Ptr CInt
exitcode
a pointer filled in with the process exit code if the process has exited, may be NULL.
-> IO (Ptr Void) 

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.

Returns
the data or NULL on failure; call getError for more information.
Thread safety
This function is not thread safe.
See also
createProcess, createProcessWithProperties, destroyProcess

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_ReadProcess. The unsafe flavor is readProcess : blocks until the process closes its output.
C declaration
SDL_ReadProcess, defined at SDL3/SDL_process.h 308:36

Since: 3.2.0

getProcessInput Source #

Arguments

:: Ptr SDL_Process
process
The process to get the input stream for.
-> IO (Ptr SDL_IOStream) 

Get the SDL_IOStream associated with process standard input.

The process must have been created with createProcess and pipe_stdio set to true, or with 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 getProcessOutput and read the output in parallel with writing input.

Returns
the input stream or NULL on failure; call getError for more information.
Thread safety
It is safe to call this function from any thread.
See also
createProcess, createProcessWithProperties, getProcessOutput

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_GetProcessInput. The safe flavor is getProcessInputSafe .
C declaration
SDL_GetProcessInput, defined at SDL3/SDL_process.h 334:44

Since: 3.2.0

getProcessInputSafe Source #

Arguments

:: Ptr SDL_Process
process
The process to get the input stream for.
-> IO (Ptr SDL_IOStream) 

Get the SDL_IOStream associated with process standard input.

The process must have been created with createProcess and pipe_stdio set to true, or with 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 getProcessOutput and read the output in parallel with writing input.

Returns
the input stream or NULL on failure; call getError for more information.
Thread safety
It is safe to call this function from any thread.
See also
createProcess, createProcessWithProperties, getProcessOutput

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_GetProcessInput. The unsafe flavor is getProcessInput .
C declaration
SDL_GetProcessInput, defined at SDL3/SDL_process.h 334:44

Since: 3.2.0

getProcessOutput Source #

Arguments

:: Ptr SDL_Process
process
The process to get the output stream for.
-> IO (Ptr SDL_IOStream) 

Get the SDL_IOStream associated with process standard output.

The process must have been created with createProcess and pipe_stdio set to true, or with createProcessWithProperties and sDL_PROP_PROCESS_CREATE_STDOUT_NUMBER set to SDL_PROCESS_STDIO_APP.

Reading from this stream can return 0 with getIOStatus returning SDL_IO_STATUS_NOT_READY if no output is available yet.

Returns
the output stream or NULL on failure; call getError for more information.
Thread safety
It is safe to call this function from any thread.
See also
createProcess, createProcessWithProperties, getProcessInput

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_GetProcessOutput. The safe flavor is getProcessOutputSafe .
C declaration
SDL_GetProcessOutput, defined at SDL3/SDL_process.h 358:44

Since: 3.2.0

getProcessOutputSafe Source #

Arguments

:: Ptr SDL_Process
process
The process to get the output stream for.
-> IO (Ptr SDL_IOStream) 

Get the SDL_IOStream associated with process standard output.

The process must have been created with createProcess and pipe_stdio set to true, or with createProcessWithProperties and sDL_PROP_PROCESS_CREATE_STDOUT_NUMBER set to SDL_PROCESS_STDIO_APP.

Reading from this stream can return 0 with getIOStatus returning SDL_IO_STATUS_NOT_READY if no output is available yet.

Returns
the output stream or NULL on failure; call getError for more information.
Thread safety
It is safe to call this function from any thread.
See also
createProcess, createProcessWithProperties, getProcessInput

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_GetProcessOutput. The unsafe flavor is getProcessOutput .
C declaration
SDL_GetProcessOutput, defined at SDL3/SDL_process.h 358:44

Since: 3.2.0

killProcess Source #

Arguments

:: Ptr SDL_Process
process
The process to stop.
-> Bool
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.
-> IO Bool 

Stop a process.

Returns
true on success or false on failure; call getError for more information.
Thread safety
This function is not thread safe.
See also
createProcess, createProcessWithProperties, waitProcess, destroyProcess

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_KillProcess. The safe flavor is killProcessSafe .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_KillProcess, defined at SDL3/SDL_process.h 381:34

Since: 3.2.0

killProcessSafe Source #

Arguments

:: Ptr SDL_Process
process
The process to stop.
-> Bool
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.
-> IO Bool 

Stop a process.

Returns
true on success or false on failure; call getError for more information.
Thread safety
This function is not thread safe.
See also
createProcess, createProcessWithProperties, waitProcess, destroyProcess

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_KillProcess. The unsafe flavor is killProcess .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_KillProcess, defined at SDL3/SDL_process.h 381:34

Since: 3.2.0

waitProcess Source #

Arguments

:: Ptr SDL_Process
process
The process to wait for.
-> Bool
block
If true, block until the process finishes; otherwise, report on the process' status.
-> Ptr CInt
exitcode
a pointer filled in with the process exit code if the process has exited, may be NULL.
-> IO Bool 

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 waitProcess. If you don't do this the process might be blocked indefinitely waiting for output to be read and waitProcess will never return true;

Returns
true if the process exited, false otherwise.
Thread safety
This function is not thread safe.
See also
createProcess, createProcessWithProperties, killProcess, destroyProcess

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_WaitProcess. The safe flavor is waitProcessSafe : blocks until the process exits.
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_WaitProcess, defined at SDL3/SDL_process.h 414:34

Since: 3.2.0

waitProcessSafe Source #

Arguments

:: Ptr SDL_Process
process
The process to wait for.
-> Bool
block
If true, block until the process finishes; otherwise, report on the process' status.
-> Ptr CInt
exitcode
a pointer filled in with the process exit code if the process has exited, may be NULL.
-> IO Bool 

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 waitProcess. If you don't do this the process might be blocked indefinitely waiting for output to be read and waitProcess will never return true;

Returns
true if the process exited, false otherwise.
Thread safety
This function is not thread safe.
See also
createProcess, createProcessWithProperties, killProcess, destroyProcess

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_WaitProcess. The unsafe flavor is waitProcess : blocks until the process exits.
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_WaitProcess, defined at SDL3/SDL_process.h 414:34

Since: 3.2.0

destroyProcess Source #

Arguments

:: Ptr SDL_Process
process
The process object to destroy.
-> IO () 

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 killProcess.

Thread safety
This function is not thread safe.
See also
createProcess, createProcessWithProperties, killProcess

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_DestroyProcess. The safe flavor is destroyProcessSafe .
C declaration
SDL_DestroyProcess, defined at SDL3/SDL_process.h 433:34

Since: 3.2.0

destroyProcessSafe Source #

Arguments

:: Ptr SDL_Process
process
The process object to destroy.
-> IO () 

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 killProcess.

Thread safety
This function is not thread safe.
See also
createProcess, createProcessWithProperties, killProcess

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_DestroyProcess. The unsafe flavor is destroyProcess .
C declaration
SDL_DestroyProcess, defined at SDL3/SDL_process.h 433:34

Since: 3.2.0