SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
SDL::Process Struct Reference

Handle to an owned process. More...

Inheritance diagram for SDL::Process:
Inheritance graph
[legend]

Public Member Functions

void Destroy ()
 Destroy a previously created process object.
 
ProcessShared share ()
 Move this process into a ProcessShared.
 
constexpr ResourceUnique (std::nullptr_t=nullptr)
 Default constructor.
 
constexpr ResourceUnique (base::value_type value, DELETER deleter={})
 Constructs from raw type.
 
constexpr ResourceUnique (ResourceUnique &&other)
 Move constructor.
 
 ResourceUnique (const ResourceUnique &other)=delete
 
- Public Member Functions inherited from SDL::ResourceUnique< ProcessRef >
constexpr ResourceUnique (std::nullptr_t=nullptr)
 Default constructor.
 
constexpr ResourceUnique (base::value_type value, DefaultDeleter< ProcessRef > deleter={})
 Constructs from raw type.
 
constexpr ResourceUnique (ResourceUnique &&other)
 Move constructor.
 
 ResourceUnique (const ResourceUnique &other)=delete
 
 ~ResourceUnique ()
 Destructor.
 
constexpr ResourceUniqueoperator= (ResourceUnique other)
 Assignment operator.
 
void reset ()
 Resets the value, destroying the resource if not nullptr.
 
- Public Member Functions inherited from SDL::ResourceOwnerBase< RESOURCE, DELETER >
RESOURCE release ()
 Returns reference and reset this.
 
- Public Member Functions inherited from SDL::ResourcePtrBase< RESOURCE >
constexpr operator bool () const
 Check if not null.
 
constexpr bool operator== (const ResourcePtrBase &other) const
 Comparison.
 
constexpr bool operator== (std::nullptr_t) const
 Comparison.
 
constexpr bool operator== (std::nullopt_t) const
 Comparison.
 
constexpr reference operator* () const
 Gets reference.
 
constexpr const referenceoperator-> () const
 Gets addressable reference.
 
constexpr referenceoperator-> ()
 Gets addressable reference.
 
reference get () const
 Get reference.
 

Static Public Member Functions

static Process Create (const char *const *args, bool pipe_stdio)
 Create a new process.
 
static Process CreateWithProperties (PropertiesRef props)
 Create a new process with the specified properties.
 

Additional Inherited Members

- Public Types inherited from SDL::ResourceOwnerBase< RESOURCE, DELETER >
using deleter = DELETER
 The deleter type.
 
- Public Types inherited from SDL::ResourcePtrBase< RESOURCE >
using reference = RESOURCE
 The reference resource type.
 
using value_type = typename reference::value_type
 The raw resource type.
 
- Protected Member Functions inherited from SDL::ResourceOwnerBase< RESOURCE, DELETER >
constexpr ResourceOwnerBase (base::value_type value={}, DELETER deleter={})
 Constructs from raw type.
 
void free ()
 Frees resource.
 
- Protected Member Functions inherited from SDL::ResourcePtrBase< RESOURCE >
constexpr ResourcePtrBase (value_type value={})
 Constructs from raw type.
 
referenceget ()
 Get reference.
 

Detailed Description

Category:
Resource
See also
ProcessRef

Member Function Documentation

◆ Create()

static Process SDL::Process::Create ( const char *const *  args,
bool  pipe_stdio 
)
inlinestatic

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

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

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 ProcessRef.Read() or ProcessRef.GetInput() and ProcessRef.GetOutput().

See Process.CreateWithProperties() for more details.

Parameters
argsthe path and arguments for the new process.
pipe_stdiotrue 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.
Returns
the newly created and running process, or nullptr if the process couldn't be created.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
Process.CreateWithProperties
ProcessRef.GetProperties
ProcessRef.Read
ProcessRef.GetInput
ProcessRef.GetOutput
ProcessRef.Kill
ProcessRef.Wait
Process.Destroy

◆ CreateWithProperties()

static Process SDL::Process::CreateWithProperties ( PropertiesRef  props)
inlinestatic

These are the supported properties:

  • prop::process.CREATE_ARGS_POINTER: an array of strings containing the program to run, any arguments, and a nullptr pointer, e.g. const char *args[] = { "myprogram", "argument", nullptr }. This is a required property.
  • prop::process.CREATE_ENVIRONMENT_POINTER: an EnvironmentRef pointer. If this property is set, it will be the entire environment for the process, otherwise the current environment is used.
  • prop::process.CREATE_STDIN_NUMBER: an ProcessIO value describing where standard input for the process comes from, defaults to SDL_PROCESS_STDIO_NULL.
  • prop::process.CREATE_STDIN_POINTER: an IOStreamRef pointer used for standard input when prop::process.CREATE_STDIN_NUMBER is set to PROCESS_STDIO_REDIRECT.
  • prop::process.CREATE_STDOUT_NUMBER: an ProcessIO value describing where standard output for the process goes to, defaults to PROCESS_STDIO_INHERITED.
  • prop::process.CREATE_STDOUT_POINTER: an IOStreamRef pointer used for standard output when prop::process.CREATE_STDOUT_NUMBER is set to PROCESS_STDIO_REDIRECT.
  • prop::process.CREATE_STDERR_NUMBER: an ProcessIO value describing where standard error for the process goes to, defaults to PROCESS_STDIO_INHERITED.
  • prop::process.CREATE_STDERR_POINTER: an IOStreamRef pointer used for standard error when prop::process.CREATE_STDERR_NUMBER is set to PROCESS_STDIO_REDIRECT.
  • prop::process.CREATE_STDERR_TO_STDOUT_BOOLEAN: true if the error output of the process should be redirected into the standard output of the process. This property has no effect if prop::process.CREATE_STDERR_NUMBER is set.
  • prop::process.CREATE_BACKGROUND_BOOLEAN: true if the process should run in the background. In this case the default input and output is SDL_PROCESS_STDIO_NULL and the exitcode of the process is not available, and will always be 0.

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 ProcessRef.Wait() instead.

Parameters
propsthe properties to use.
Returns
the newly created and running process, or nullptr if the process couldn't be created.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
Process.Create
ProcessRef.GetProperties
ProcessRef.Read
ProcessRef.GetInput
ProcessRef.GetOutput
ProcessRef.Kill
ProcessRef.Wait
Process.Destroy

◆ Destroy()

void SDL::Process::Destroy ( )
inline

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 ProcessRef.Kill().

Thread safety:
This function is not thread safe.
Since
This function is available since SDL 3.2.0.
See also
Process.Create
Process.CreateWithProperties
ProcessRef.Kill

The documentation for this struct was generated from the following file: