SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL::ProcessRef Struct Reference

Reference for Process. More...

Inheritance diagram for SDL::ProcessRef:
[legend]

Public Member Functions

constexpr ProcessRef (ProcessRaw resource) noexcept
 Constructs from raw Process.
constexpr ProcessRef (const Process &resource) noexcept
 Constructs from Process.
constexpr ProcessRef (Process &&resource) noexcept
 Constructs from Process.
constexpr ProcessRef (const ProcessRef &other) noexcept
 Copy constructor.
constexpr ProcessRef (ProcessRef &&other) noexcept
 Move constructor.
 ~ProcessRef ()
 Destructor.
ProcessRefoperator= (const ProcessRef &other) noexcept
 Assignment operator.
constexpr operator ProcessRaw () const noexcept
 Converts to ProcessRaw.
constexpr Process (std::nullptr_t=nullptr) noexcept
 Default ctor.
constexpr Process (ProcessRaw resource) noexcept
 Constructs from raw Process.
constexpr Process (const Process &other) noexcept=delete
 Copy constructor.
constexpr Process (Process &&other) noexcept
 Move constructor.
constexpr Process (const ProcessRef &other)=delete
constexpr Process (ProcessRef &&other)=delete
 Process (const char *const *args, bool pipe_stdio)
 Create a new process.
 Process (PropertiesRef props)
 Create a new process with the specified properties.
Public Member Functions inherited from SDL::Process
constexpr Process (std::nullptr_t=nullptr) noexcept
 Default ctor.
constexpr Process (ProcessRaw resource) noexcept
 Constructs from raw Process.
constexpr Process (const Process &other) noexcept=delete
 Copy constructor.
constexpr Process (Process &&other) noexcept
 Move constructor.
constexpr Process (const ProcessRef &other)=delete
constexpr Process (ProcessRef &&other)=delete
 Process (const char *const *args, bool pipe_stdio)
 Create a new process.
 Process (PropertiesRef props)
 Create a new process with the specified properties.
 ~Process ()
 Destructor.
constexpr Processoperator= (Process &&other) noexcept
 Assignment operator.
Processoperator= (const Process &other)=delete
 Assignment operator.
constexpr ProcessRaw get () const noexcept
 Retrieves underlying ProcessRaw.
constexpr ProcessRaw release () noexcept
 Retrieves underlying ProcessRaw and clear this.
constexpr auto operator<=> (const Process &other) const noexcept=default
 Comparison.
constexpr operator bool () const noexcept
 Converts to bool.
void Destroy ()
 Destroy a previously created process object.
PropertiesRef GetProperties () const
 Get the properties associated with a process.
StringResult Read (int *exitcode=nullptr)
 Read all the output from a process.
template<class T>
OwnArray< T > ReadAs (int *exitcode=nullptr)
 Read all the output from a process.
IOStreamRef GetInput ()
 Get the IOStream associated with process standard input.
IOStreamRef GetOutput ()
 Get the IOStream associated with process standard output.
void Kill (bool force)
 Stop a process.
bool Wait (bool block, int *exitcode)
 Wait for a process to finish.

Detailed Description

Reference for Process.

This does not take ownership!

Constructor & Destructor Documentation

◆ ProcessRef() [1/3]

SDL::ProcessRef::ProcessRef ( ProcessRaw resource)
inlineconstexprnoexcept

Constructs from raw Process.

Parameters
resourcea ProcessRaw.

This does not takes ownership!

◆ ProcessRef() [2/3]

SDL::ProcessRef::ProcessRef ( const Process & resource)
inlineconstexprnoexcept

Constructs from Process.

Parameters
resourcea Process.

This does not takes ownership!

◆ ProcessRef() [3/3]

SDL::ProcessRef::ProcessRef ( Process && resource)
inlineconstexprnoexcept

Constructs from Process.

Parameters
resourcea Process.

This will release the ownership from resource!

Member Function Documentation

◆ Process() [1/3]

SDL::Process::Process ( const char *const * args,
bool pipe_stdio )
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.:

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

See CreateProcessWithProperties() 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.
Postcondition
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
CreateProcessWithProperties
Process.GetProperties
Process.Read
Process.GetInput
Process.GetOutput
Process.Kill
Process.Wait
Process.Destroy

◆ Process() [2/3]

SDL::Process::Process ( ProcessRaw resource)
inlineexplicitconstexprnoexcept

Constructs from raw Process.

Parameters
resourcea ProcessRaw to be wrapped.

This assumes the ownership, call release() if you need to take back.

◆ Process() [3/3]

Create a new process with the specified properties.

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 Environment pointer. If this property is set, it will be the entire environment for the process, otherwise the current environment is used.
  • prop::process.CREATE_WORKING_DIRECTORY_STRING: a UTF-8 encoded string representing the working directory for the process, defaults to the current working directory.
  • prop::process.CREATE_STDIN_NUMBER: an ProcessIO value describing where standard input for the process comes from, defaults to SDL_PROCESS_STDIO_nullptr.
  • prop::process.CREATE_STDIN_POINTER: an IOStream 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 IOStream 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 IOStream 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_nullptr and the exitcode of the process is not available, and will always be 0.
  • prop::process.CREATE_CMDLINE_STRING: a string containing the program to run and any parameters. This string is passed directly to CreateProcess on Windows, and does nothing on other platforms. This property is only important if you want to start programs that does non-standard command-line processing, and in most cases using prop::process.CREATE_ARGS_POINTER is sufficient.

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.

Parameters
propsthe properties to use.
Postcondition
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
CreateProcess
Process.GetProperties
Process.Read
Process.GetInput
Process.GetOutput
Process.Kill
Process.Wait
Process.Destroy

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