Creates a process and executes a program.
More...
#include <Process.h>
|
| enum | Error {
UnknownError
, BusyError
, PipeError
, SpawnError
,
WaitPidError
, ReadError
, WriteError
} |
| | Errors returned by lastErrorNo().
|
|
| bool | run (const std::filesystem::path &program, const std::vector< std::string > &args={}, std::string *out=nullptr) |
| | Spawns a process, executes program with args, and waits for its termination.
|
| bool | spawn (const std::filesystem::path &program, const std::vector< std::string > &args={}, bool captureStdout=false) |
| | Forks a process and executes program with args.
|
| bool | readAll (std::string &out) |
| | Read everything from process' stdout.
|
| int | readPipe () const |
| | Get the stdout pipe of the process.
|
| bool | waitForFinished () |
| | Wait until the underlying process is finished (or dead).
|
|
bool | kill (int sig) |
| | Send a signal sig to the process.
|
| pid_t | pid () const |
| | Return the process ID for the child process.
|
| bool | signalled () const |
| | Was the child signalled?
|
| unsigned int | exitStatus () const |
| | Exit status of the children (aka WEXITSTATUS()).
|
|
const std::string & | lastError () const |
| | Return the last error string if some.
|
|
Error | lastErrorNo () const |
| | Return the last error number.
|
Creates a process and executes a program.
◆ exitStatus()
| unsigned int SlHelpers::Process::exitStatus |
( |
| ) |
const |
|
inline |
Exit status of the children (aka WEXITSTATUS()).
- Returns
- Exit status.
◆ pid()
| pid_t SlHelpers::Process::pid |
( |
| ) |
const |
|
inline |
Return the process ID for the child process.
- Returns
- PID
◆ readAll()
| bool SlHelpers::Process::readAll |
( |
std::string & | out | ) |
|
Read everything from process' stdout.
- Parameters
-
- Returns
- true on success.
◆ readPipe()
| int SlHelpers::Process::readPipe |
( |
| ) |
const |
|
inline |
Get the stdout pipe of the process.
- Returns
- Pipe file descriptor.
◆ run()
| bool SlHelpers::Process::run |
( |
const std::filesystem::path & | program, |
|
|
const std::vector< std::string > & | args = {}, |
|
|
std::string * | out = nullptr ) |
Spawns a process, executes program with args, and waits for its termination.
- Parameters
-
| program | Program to execute |
| args | Arguments passed to the program (do not add program itself) |
| out | stdout of the program |
- Returns
- zero on success
If out is non-NULL, the stdout of the program is filled in there. run() combines spawn(), readAll(), and waitForFinished().
◆ signalled()
| bool SlHelpers::Process::signalled |
( |
| ) |
const |
|
inline |
Was the child signalled?
- Returns
- true if signalled.
◆ spawn()
| bool SlHelpers::Process::spawn |
( |
const std::filesystem::path & | program, |
|
|
const std::vector< std::string > & | args = {}, |
|
|
bool | captureStdout = false ) |
Forks a process and executes program with args.
- Parameters
-
| program | Program to run |
| args | Arguments to pass to program |
| captureStdout | Stdout of the program. If nullptr, output is discarded |
- Returns
- true on success.
◆ waitForFinished()
| bool SlHelpers::Process::waitForFinished |
( |
| ) |
|
Wait until the underlying process is finished (or dead).
- Returns
- true on success.
The documentation for this class was generated from the following file:
- /home/abuild/rpmbuild/BUILD/slhelpers-20260428.f233ce9-build/slhelpers-20260428.f233ce9/include/helpers/Process.h