Execute a child process with standard file descriptors redirection. More...
#include <Process.h>
Classes | |
struct | Options |
struct | StdIn |
struct | StdOut |
struct | StdStream |
Public Types | |
using | StdErr = StdOut |
Public Member Functions | |
Result | waitForExitSync () |
Waits (blocking) for process to exit after launch. It can only be called if Process::launch succeeded. More... | |
Result | launch (Span< const StringView > cmd, const StdOut &stdOut=StdOut::Inherit{}, const StdIn &stdIn=StdIn::Inherit{}, const StdErr &stdErr=StdErr::Inherit{}) |
Launch child process with the given arguments. More... | |
Result | exec (Span< const StringView > cmd, const StdOut &stdOut=StdOut::Inherit{}, const StdIn &stdIn=StdIn::Inherit{}, const StdErr &stdErr=StdErr::Inherit{}) |
Executes a child process with the given arguments, waiting (blocking) until it's fully finished. More... | |
int32_t | getExitStatus () const |
gets the return code from the exited child process (valid only after exec or waitForExitSync) More... | |
Result | setWorkingDirectory (StringView processWorkingDirectory) |
Sets the starting working directory of the process that will be launched / executed. More... | |
void | inheritParentEnvironmentVariables (bool inherit) |
Controls if the newly spawned child process will inherit parent process environment variables. More... | |
Result | setEnvironment (StringView environmentVariable, StringView value) |
Sets the environment variable for the newly spawned child process. More... | |
Static Public Member Functions | |
static size_t | getNumberOfProcessors () |
Returns number of (virtual) processors available. More... | |
static bool | isWindowsConsoleSubsystem () |
Returns true only under Windows if executable is compiled with /SUBSYSTEM:Console More... | |
Public Attributes | |
ProcessDescriptor | handle |
Handle to the OS process. More... | |
ProcessID | processID |
ID of the process (can be the same as handle on some OS) More... | |
Options | options |
Options for the child process (hide console window etc.) More... | |
Friends | |
struct | IntrusiveDoubleLinkedList< Process > |
struct | ProcessChain |
Execute a child process with standard file descriptors redirection.
Features:
Example: execute child process (launch and wait for it to fully execute)
Example: execute child process, redirecting stdout to a string
Example: launch a child process and wait for it to finish execution
Example: execute child process, filling its stdin with a StringView
Example: read process output using a pipe, using launch + waitForExitSync
Example: Add an environment variable
Example: Redefine an environment variable
Example: Disable environment variable inheritance
|
inline |
Executes a child process with the given arguments, waiting (blocking) until it's fully finished.
cmd | Process executable path and its arguments (if any) |
stdOut | Process::StdOut::Ignore{}, Process::StdOut::Inherit{} or redirect stdout to String/Vector/Span |
stdIn | Process::StdIn::Ignore{}, Process::StdIn::Inherit{} or feed stdin from StringView/String/Vector/Span |
stdErr | Process::StdErr::Ignore{}, Process::StdErr::Inherit{} or redirect stderr to String/Vector/Span |
|
inline |
gets the return code from the exited child process (valid only after exec or waitForExitSync)
|
static |
Returns number of (virtual) processors available.
|
inline |
Controls if the newly spawned child process will inherit parent process environment variables.
|
static |
Returns true only under Windows if executable is compiled with /SUBSYSTEM:Console
|
inline |
Launch child process with the given arguments.
cmd | Process executable path and its arguments (if any) |
stdOut | Process::StdOut::Ignore{}, Process::StdOut::Inherit{} or redirect stdout to String/Vector/Span |
stdIn | Process::StdIn::Ignore{}, Process::StdIn::Inherit{} or feed stdin from StringView/String/Vector/Span |
stdErr | Process::StdErr::Ignore{}, Process::StdErr::Inherit{} or redirect stderr to String/Vector/Span |
Result SC::Process::setEnvironment | ( | StringView | environmentVariable, |
StringView | value | ||
) |
Sets the environment variable for the newly spawned child process.
Result SC::Process::setWorkingDirectory | ( | StringView | processWorkingDirectory | ) |
Sets the starting working directory of the process that will be launched / executed.
Result SC::Process::waitForExitSync | ( | ) |
Waits (blocking) for process to exit after launch. It can only be called if Process::launch succeeded.
ProcessDescriptor SC::Process::handle |
Handle to the OS process.
ProcessID SC::Process::processID |
ID of the process (can be the same as handle on some OS)