|
blocxx
|
Namespaces | |
| namespace | Impl |
Classes | |
| class | InputCallback |
| class | OutputCallback |
| class | PreExec |
| This class is used to specify what spawn() should do between fork and exec. More... | |
Enumerations | |
| enum | EOutputSource { E_STDOUT , E_STDERR } |
Variables | |
| ::BLOCXX_NAMESPACE::GlobalPtr< ExecMockObject, Impl::NullFactory > | g_execMockObject = { 0, {0, PTHREAD_MUTEX_INITIALIZER} } |
| static char const *const *const | currentEnvironment = 0 |
| Intended to be used as a parameter to spawn() to indicate that the current environment will be used for the child process. | |
| BLOCXX_COMMON_API Process::Status BLOCXX_NAMESPACE::Exec::executeProcessAndGatherOutput | ( | char const *const | command[], |
| String & | output, | ||
| char const *const | envVars[], | ||
| const Timeout & | timeout = Timeout::infinite, | ||
| int | outputlimit = -1, | ||
| char const * | input = 0 ) |
Execute a command and run feedProcessAndGatherOutput() on the process.
This function will not search the path for command[0], so the absolute path to the binary should be specified. If the path needs to be searched, you can set command[0] = "/bin/sh"; command[1] = "-c"; and then fill in the rest of the array with the command you wish to execute. Exercise caution when doing this, as you may be creating a security hole.
| command | command[0] is the binary to be executed. command[1] .. command[n] are the command line parameters to the command. |
| output |
| envVars | An EnvVars object that contains the environment variables to pass as the environment to the new process. If envVars doesn't contain any environment variables, then the current process's environment variables will be used. |
| timeout |
| outputlimit |
| input |
| ExecErrorException | on error. |
| ExecTimeoutException | if the process hasn't finished within timeoutsecs. |
| ExecBufferFullException | if the process output exceeds outputlimit bytes. |
Definition at line 257 of file Exec.cpp.
References feedProcessAndGatherOutput(), g_execMockObject, BLOCXX_NAMESPACE::operator==(), and spawn().
Referenced by executeProcessAndGatherOutput(), executeProcessAndGatherOutput(), executeProcessAndGatherOutput(), executeProcessAndGatherOutput(), executeProcessAndGatherOutput(), executeProcessAndGatherOutput(), executeProcessAndGatherOutput(), and executeProcessAndGatherOutput().
| BLOCXX_COMMON_API Process::Status BLOCXX_NAMESPACE::Exec::executeProcessAndGatherOutput | ( | char const *const | command[], |
| String & | output, | ||
| String & | erroutput, | ||
| char const *const | envVars[], | ||
| const Timeout & | timeout = Timeout::infinite, | ||
| int | outputLimit = -1, | ||
| char const * | input = 0 ) |
Execute a command and run feedProcessAndGatherOutput() on the process.
This function will not search the path for command[0], so the absolute path to the binary should be specified. If the path needs to be searched, you can set command[0] = "/bin/sh"; command[1] = "-c"; and then fill in the rest of the array with the command you wish to execute. Exercise caution when doing this, as you may be creating a security hole.
| command | command[0] is the binary to be executed. command[1] .. command[n] are the command line parameters to the command. |
| output |
| erroutput |
| envVars | An EnvVars object that contains the environment variables to pass as the environment to the new process. If envVars doesn't contain any environment variables, then the current process's environment variables will be used. |
| timeout |
| outputlimit |
| input |
| ExecErrorException | on error. |
| ExecTimeoutException | if the process hasn't finished within timeoutsecs. |
| ExecBufferFullException | if the process output exceeds outputlimit bytes. |
Definition at line 274 of file Exec.cpp.
References feedProcessAndGatherOutput(), g_execMockObject, BLOCXX_NAMESPACE::operator==(), and spawn().
| BLOCXX_COMMON_API void BLOCXX_NAMESPACE::Exec::executeProcessAndGatherOutput | ( | const Array< String > & | command, |
| String & | output, | ||
| int & | processstatus, | ||
| int | timeoutsecs, | ||
| int | outputlimit, | ||
| const String & | input ) |
Definition at line 294 of file Exec.cpp.
References executeProcessAndGatherOutput(), BLOCXX_NAMESPACE::Timeout::infinite, BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::Timeout::relative().
| Process::Status BLOCXX_NAMESPACE::Exec::executeProcessAndGatherOutput | ( | SA1 const & | command, |
| S1 & | output, | ||
| const Timeout & | timeout, | ||
| int | outputlimit, | ||
| S2 const & | input ) |
Version of executeProcessAndGatherOutput() that passes the current process's environment to the child process.
Definition at line 576 of file Exec.hpp.
References currentEnvironment, executeProcessAndGatherOutput(), BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::Cstr::to_char_ptr().
| Process::Status BLOCXX_NAMESPACE::Exec::executeProcessAndGatherOutput | ( | SA1 const & | command, |
| S1 & | output, | ||
| const Timeout & | timeout = Timeout::infinite, | ||
| int | outputlimit = -1 ) |
Version of executeProcessAndGatherOutput() that passes the current process's environment to the child process.
Definition at line 633 of file Exec.hpp.
References currentEnvironment, executeProcessAndGatherOutput(), and BLOCXX_NAMESPACE::operator==().
| Process::Status BLOCXX_NAMESPACE::Exec::executeProcessAndGatherOutput | ( | SA1 const & | command, |
| S1 & | output, | ||
| S1 & | erroutput, | ||
| const Timeout & | timeout, | ||
| int | outputlimit, | ||
| S2 const & | input ) |
Version of executeProcessAndGatherOutput() that passes the current process's environment to the child process and separates STDOUT and STDERR.
Definition at line 604 of file Exec.hpp.
References currentEnvironment, executeProcessAndGatherOutput(), BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::Cstr::to_char_ptr().
| Process::Status BLOCXX_NAMESPACE::Exec::executeProcessAndGatherOutput | ( | SA1 const & | command, |
| S1 & | output, | ||
| S1 & | erroutput, | ||
| const Timeout & | timeout = Timeout::infinite, | ||
| int | outputlimit = -1 ) |
Version of executeProcessAndGatherOutput() that passes the current process's environment to the child process and collects STDOUT and STDERR separately.
Definition at line 660 of file Exec.hpp.
References currentEnvironment, executeProcessAndGatherOutput(), and BLOCXX_NAMESPACE::operator==().
| Process::Status BLOCXX_NAMESPACE::Exec::executeProcessAndGatherOutput | ( | SA1 const & | command, |
| S1 & | output, | ||
| S1 & | erroutput, | ||
| SA2 const & | envp, | ||
| const Timeout & | timeout, | ||
| int | outputlimit, | ||
| S2 const & | input ) |
Variant of executeProcessAndGatherOutput that allows command and envp to have arbitrary string-array-like types and output to have an arbitrary string-like type.
It also collects STDOUT and STDERR separately. If command or envp are of type StringArray a terminating null is not necessary.
Cstr::to_char_ptr is defined.Cstr::CstrArr class template are defined for both types SA1 and SA2. Definition at line 736 of file Exec.hpp.
References executeProcessAndGatherOutput(), BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::Cstr::to_char_ptr().
| Process::Status BLOCXX_NAMESPACE::Exec::executeProcessAndGatherOutput | ( | SA1 const & | command, |
| S1 & | output, | ||
| S1 & | erroutput, | ||
| SA2 const & | envp, | ||
| const Timeout & | timeout = Timeout::infinite, | ||
| int | outputlimit = -1 ) |
Version of executeProcessAndGatherOutput() that passes no input to the process.
STDOUT and STDERR are collected separately.
Definition at line 766 of file Exec.hpp.
References executeProcessAndGatherOutput(), and BLOCXX_NAMESPACE::operator==().
| Process::Status BLOCXX_NAMESPACE::Exec::executeProcessAndGatherOutput | ( | SA1 const & | command, |
| S1 & | output, | ||
| SA2 const & | envp, | ||
| const Timeout & | timeout, | ||
| int | outputlimit, | ||
| S2 const & | input ) |
Variant of executeProcessAndGatherOutput that allows command and envp to have arbitrary string-array-like types and output to have an arbitrary string-like type.
If command or envp are of type StringArray a terminating null is not necessary.
Cstr::to_char_ptr is defined.Cstr::CstrArr class template are defined for both types SA1 and SA2. Definition at line 698 of file Exec.hpp.
References executeProcessAndGatherOutput(), BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::Cstr::to_char_ptr().
| BLOCXX_COMMON_API Process::Status BLOCXX_NAMESPACE::Exec::feedProcessAndGatherOutput | ( | ProcessRef const & | proc, |
| String & | output, | ||
| String & | erroutput, | ||
| Timeout const & | timeout = Timeout::infinite, | ||
| int | outputLimit = -1, | ||
| String const & | input = String() ) |
Send input to a process, collect STDOUT and STDERR, and wait for it to exit.
The function returns when the process exits. In the case that the child process doesn't exit, if a timout is specified, then an ExecTimeoutException is thrown. If the process outputs more bytes than outputlimit on STDOUT or STDERR, an ExecBufferFullException is thrown.
If the process does not terminate by itself, or if an exception is thrown because a limit has been reached (time or output), then Process::waitCloseTerm() is called with default arguments to force termination.
| proc | The object managing the process. |
| output | Process STDOUT is appended to this string. |
| erroutut | Process STDERR is appended to this string. |
| timeout | The interval to wait for the process to exit. If the process hasn't exited after the timeout, an ExecTimeoutException will be thrown, and the process will be killed. Output from a process can reset a relative with reset timeout. |
| outputlimit | The maximum size of the parameter output, in order to constrain possible memory usage. If the process outputs more data than will fit into output, then an ExecBufferFullException is thrown, and the process will be killed. If outputlimit < 0, the limit will be infinite, and an ExecBufferFullException will not be thrown. |
| input | Data to write to the child's stdin. After the data has been written, stdin is closed. |
| ExecErrorException | on error. |
| ExecTimeoutException | if the process hasn't finished within timeoutsecs. |
| ExecBufferFullException | if the process output exceeds outputlimit bytes. |
Definition at line 331 of file Exec.cpp.
References BLOCXX_NAMESPACE::operator==(), and processInputOutput().
| BLOCXX_COMMON_API Process::Status BLOCXX_NAMESPACE::Exec::feedProcessAndGatherOutput | ( | ProcessRef const & | proc, |
| String & | output, | ||
| Timeout const & | timeout = Timeout::infinite, | ||
| int | outputlimit = -1, | ||
| String const & | input = String() ) |
Send input to a process, collect the output, and wait for it to exit.
The function returns when the process exits. In the case that the child process doesn't exit, if a timout is specified, then an ExecTimeoutException is thrown. If the process outputs more bytes than outputlimit, an ExecBufferFullException is thrown.
If the process does not terminate by itself, or if an exception is thrown because a limit has been reached (time or output), then Process::waitCloseTerm() is called with default arguments to force termination.
| proc | The object managing the process. |
| output | Process output is appended to this string. |
| timeout | The interval to wait for the process to exit. If the process hasn't exited after the timeout, an ExecTimeoutException will be thrown, and the process will be killed. Output from a process can reset a relative with reset timeout. |
| outputlimit | The maximum size of the parameter output, in order to constrain possible memory usage. If the process outputs more data than will fit into output, then an ExecBufferFullException is thrown, and the process will be killed. If outputlimit < 0, the limit will be infinite, and an ExecBufferFullException will not be thrown. |
| input | Data to write to the child's stdin. After the data has been written, stdin is closed. |
| ExecErrorException | on error. |
| ExecTimeoutException | if the process hasn't finished within timeoutsecs. |
| ExecBufferFullException | if the process output exceeds outputlimit bytes. |
Definition at line 314 of file Exec.cpp.
References BLOCXX_NAMESPACE::operator==(), and processInputOutput().
Referenced by executeProcessAndGatherOutput(), and executeProcessAndGatherOutput().
| BLOCXX_COMMON_API void BLOCXX_NAMESPACE::Exec::gatherOutput | ( | String & | output, |
| const ProcessRef & | proc, | ||
| const Timeout & | timeout = Timeout::infinite, | ||
| int | outputlimit = -1 ) |
Wait for output from a child process.
The function returns when the process exits. In the case that the child process doesn't exit, if a timout is specified, then an ExecTimeoutException is thrown. If the process outputs more bytes than outputlimit, an ExecBufferFullException is thrown.
| output | An out parameter, the process output will be appended to this string. |
| proc | The connection to the child process. |
| timeout | Specifies the interval to wait for the process to exit. If the process hasn't exited after the timeout, an ExecTimeoutException will be thrown. Output from a process can reset a relative with reset timeout. |
| outputlimit | Specifies the maximum size of the parameter output, in order to constrain possible memory usage. If the process outputs more data than will fit into output, then an ExecBufferFullException is thrown. If outputlimit < 0, the limit will be infinite, and an ExecBufferFullException will never be thrown. |
| ProcessError | on error. |
| ProcessTimeout | if the process hasn't finished within timeoutsecs. |
| ProcessBufferFull | if the process output exceeds outputlimit bytes. |
Definition at line 356 of file Exec.cpp.
References BLOCXX_NAMESPACE::operator==(), and processInputOutput().
| void BLOCXX_NAMESPACE::Exec::gatherOutput | ( | String & | output, |
| const ProcessRef & | proc, | ||
| int | timeoutSecs, | ||
| int | outputLimit ) |
Definition at line 350 of file Exec.cpp.
References gatherOutput(), BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::Timeout::relativeWithReset().
Referenced by gatherOutput().
| BLOCXX_COMMON_API void BLOCXX_NAMESPACE::Exec::processInputOutput | ( | const String & | input, |
| String & | output, | ||
| const ProcessRef & | process, | ||
| const Timeout & | timeout, | ||
| int | outputLimit ) |
Definition at line 608 of file Exec.cpp.
References BLOCXX_NAMESPACE::operator==(), processInputOutput(), and BLOCXX_NAMESPACE::Array< T >::push_back().
| BLOCXX_COMMON_API void BLOCXX_NAMESPACE::Exec::processInputOutput | ( | OutputCallback & | output, |
| Array< ProcessRef > & | procs, | ||
| InputCallback & | input, | ||
| const Timeout & | timeout = Timeout::infinite ) |
Send input and wait for output from child processes.
The function returns when the processes have exited. In the case that a child process doesn't exit, if a timout is specified, then an ExecTimeoutException is thrown. If an exception is thrown by the OutputCallback or InputCallback, it will not be caught.
| output | A callback, whenever data is received from a process, it will be passed to output.handleData(). |
| procs | The connections to the child processes. |
| timeout | Specifies the interval to wait for all the processes to exit. If the timeout expires, an ExecTimeoutException will be thrown. Output from a process can reset a relative with reset timeout. |
| input | Callback to provide data to be written to the process(es) standard input. input.getData() will be called once for each stream, and subsequently once every time data has been written to a process. output.handleData() may also provide input data via the inputBuffer parameter, it is called every time data is read from a process. |
| ExecErrorException | on error. |
| ExecTimeoutException | if the process hasn't finished within timeoutSecs. |
Definition at line 412 of file Exec.cpp.
References availableDataLen, BLOCXX_THROW, BLOCXX_THROW_ERRNO_MSG, E_STDERR, E_STDOUT, errIsOpen, i, inIsOpen, BLOCXX_NAMESPACE::operator==(), outIsOpen, BLOCXX_NAMESPACE::IOIFC::read(), BLOCXX_NAMESPACE::Select::SELECT_ERROR, BLOCXX_NAMESPACE::Select::SELECT_TIMEOUT, BLOCXX_NAMESPACE::Select::selectRW(), and BLOCXX_NAMESPACE::IOIFC::write().
Referenced by feedProcessAndGatherOutput(), feedProcessAndGatherOutput(), gatherOutput(), and processInputOutput().
| BLOCXX_COMMON_API int BLOCXX_NAMESPACE::Exec::safeSystem | ( | const Array< String > & | command, |
| const char *const | envp[] = 0 ) |
This is deprecated.
Use system() instead
Definition at line 112 of file Exec.cpp.
References BLOCXX_NAMESPACE::operator==(), and system().
| BLOCXX_COMMON_API ProcessRef BLOCXX_NAMESPACE::Exec::spawn | ( | char const *const | argv[], |
| char const *const | envp[] ) |
Variant of spawn that uses StandardPreExec.
Definition at line 147 of file Exec.cpp.
References BLOCXX_NAMESPACE::operator==(), and spawn().
| BLOCXX_COMMON_API ProcessRef BLOCXX_NAMESPACE::Exec::spawn | ( | char const * | exec_path, |
| char const *const | argv[], | ||
| char const *const | envp[], | ||
| PreExec & | pre_exec ) |
Run the executable exec_path in a child process, with argv for the program arguments and envp for the environment.
| exec_path | Absolute path of the executable to run in the child process. |
| argv | Null-terminated argument list for the child process. If argv is null or the empty sequence (argv[0] is null), then it is replaced with a sequence containing only exec_path. |
| envp | The null-terminated environment for the child process. If null then the caller's environment is used. It is recommended that envp be constructed by starting with Secure::minimal_environment() and adding only those additional environment variables known to be needed. |
| pre_exec | Specifies what action to take in the child process between fork and exec. |
Definition at line 133 of file Exec.cpp.
References BLOCXX_NAMESPACE::operator==(), BLOCXX_NAMESPACE::WaitpidThreadFix::shouldUseWaitpidThreadFix(), spawnImpl(), and BLOCXX_NAMESPACE::WaitpidThreadFix::spawnProcess().
Referenced by executeProcessAndGatherOutput(), executeProcessAndGatherOutput(), spawn(), spawn(), spawn(), spawn(), and system().
| ProcessRef BLOCXX_NAMESPACE::Exec::spawn | ( | S const & | exec_path, |
| SA1 const & | argv, | ||
| SA2 const & | envp, | ||
| PreExec & | pre_exec ) |
Variant of spawn that allows exec_path to have an arbitrary string-like type, and argv and envp to have arbitrary string-array-like types.
If argv or envp are of type StringArray a terminating null is not necessary.
Cstr::to_char_ptr is defined.Cstr::CstrArr class template are defined for both types SA1 and SA2. Definition at line 247 of file Exec.hpp.
References BLOCXX_NAMESPACE::operator==(), spawn(), and BLOCXX_NAMESPACE::Cstr::to_char_ptr().
| ProcessRef BLOCXX_NAMESPACE::Exec::spawn | ( | SA1 const & | argv | ) |
Definition at line 282 of file Exec.hpp.
References currentEnvironment, BLOCXX_NAMESPACE::operator==(), and spawn().
| ProcessRef BLOCXX_NAMESPACE::Exec::spawn | ( | SA1 const & | argv, |
| SA2 const & | envp ) |
Variant of spawn that uses StandardPreExec and argv and envp to have arbitrary string-array-like types.
Cstr::CstrArr class template are defined for both types SA1 and SA2. Definition at line 272 of file Exec.hpp.
References BLOCXX_NAMESPACE::operator==(), and spawn().
Variant of spawnImpl that uses StandardPreExec.
| ProcessRef BLOCXX_NAMESPACE::Exec::spawnImpl | ( | char const * | exec_path, |
| char const *const | argv[], | ||
| char const *const | envp[], | ||
| PreExec & | pre_exec ) |
Definition at line 119 of file Exec.cpp.
References BLOCXX_NAMESPACE::operator==(), BLOCXX_NAMESPACE::PosixExec::spawnImpl(), and BLOCXX_NAMESPACE::WinExec::spawnImpl().
Referenced by spawn(), spawnImpl(), spawnImpl(), and spawnImpl().
| ProcessRef BLOCXX_NAMESPACE::Exec::spawnImpl | ( | S const & | exec_path, |
| SA1 const & | argv, | ||
| SA2 const & | envp, | ||
| PreExec & | pre_exec ) |
Variant of spawnImpl that allows exec_path to have an arbitrary string-like type, and argv and envp to have arbitrary string-array-like types.
If argv or envp are of type StringArray a terminating null is not necessary.
Cstr::to_char_ptr is defined.Cstr::CstrArr class template are defined for both types SA1 and SA2. Definition at line 70 of file WaitpidThreadFixFwd.hpp.
References BLOCXX_NAMESPACE::operator==(), spawnImpl(), and BLOCXX_NAMESPACE::Cstr::to_char_ptr().
| ProcessRef BLOCXX_NAMESPACE::Exec::spawnImpl | ( | SA1 const & | argv | ) |
Definition at line 105 of file WaitpidThreadFixFwd.hpp.
References currentEnvironment, BLOCXX_NAMESPACE::operator==(), and spawnImpl().
| ProcessRef BLOCXX_NAMESPACE::Exec::spawnImpl | ( | SA1 const & | argv, |
| SA2 const & | envp ) |
Variant of spawnImpl that uses StandardPreExec and argv and envp to have arbitrary string-array-like types.
Cstr::CstrArr class template are defined for both types SA1 and SA2. Definition at line 95 of file WaitpidThreadFixFwd.hpp.
References BLOCXX_NAMESPACE::operator==(), and spawnImpl().
| BLOCXX_COMMON_API Process::Status BLOCXX_NAMESPACE::Exec::system | ( | const Array< String > & | command, |
| const char *const | envp[] = 0, | ||
| const Timeout & | = Timeout::infinite ) |
Execute a command.
The command will inherit stdin, STDOUT, and STDERR from the parent process. This function will not search the path for command[0], so the absolute path to the binary should be specified. If the path needs to be searched, you can set command[0] = "/bin/sh"; command[1] = "-c"; and then fill in the rest of the array with the command you wish to execute. This function blocks until the child process exits. Use a timeout or be careful that the command you run doesn't hang.
| command | command[0] is the binary to be executed. command[1] .. command[n] are the command line parameters to the command. |
| envp | an array of strings of the form "key=value", which are passed as environment to the new program. envp must be terminated by a null pointer. envp may be 0, in which case the current process's environment variables will be used. |
| timeout | How long to wait for the process to exit. |
| ExecErrorException | on error |
Definition at line 94 of file Exec.cpp.
References BLOCXX_NAMESPACE::operator==(), BLOCXX_NAMESPACE::Timeout::relative(), and spawn().
Referenced by BLOCXX_NAMESPACE::StackTrace::getStackTrace(), safeSystem(), and system().
| Process::Status BLOCXX_NAMESPACE::Exec::system | ( | const SA1 & | command, |
| const SA2 & | envVars, | ||
| const Timeout & | timeout = Timeout::infinite ) |
Definition at line 88 of file Exec.hpp.
References BLOCXX_NAMESPACE::operator==(), and system().
Intended to be used as a parameter to spawn() to indicate that the current environment will be used for the child process.
Definition at line 205 of file Exec.hpp.
Referenced by executeProcessAndGatherOutput(), executeProcessAndGatherOutput(), executeProcessAndGatherOutput(), executeProcessAndGatherOutput(), spawn(), and spawnImpl().
| ::BLOCXX_NAMESPACE::GlobalPtr<ExecMockObject, Impl::NullFactory> BLOCXX_NAMESPACE::Exec::g_execMockObject = { 0, {0, PTHREAD_MUTEX_INITIALIZER} } |
Definition at line 90 of file Exec.cpp.
Referenced by executeProcessAndGatherOutput(), and executeProcessAndGatherOutput().