29 Process() : m_pid(-1), m_pipe{-1, -1}, m_signalled(false), m_exitStatus(0), m_lastError(
""),
30 m_lastErrorNo(UnknownError) {}
43 bool run(
const std::filesystem::path &program,
const std::vector<std::string> &args = {},
44 std::string *out =
nullptr);
53 bool spawn(
const std::filesystem::path &program,
const std::vector<std::string> &args = {},
54 bool captureStdout =
false);
82 pid_t
pid()
const {
return m_pid; }
97 const std::string &
lastError()
const {
return m_lastError; }
101 void closePipe(
const unsigned int &p);
102 void setError(
const Error &errNo,
const std::string &error) {
103 m_lastErrorNo = errNo;
110 unsigned int m_exitStatus;
111 std::string m_lastError;
Creates a process and executes a program.
Definition Process.h:16
Error lastErrorNo() const
Return the last error number.
Definition Process.h:99
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.
pid_t pid() const
Return the process ID for the child process.
Definition Process.h:82
unsigned int exitStatus() const
Exit status of the children (aka WEXITSTATUS()).
Definition Process.h:94
bool readAll(std::string &out)
Read everything from process' stdout.
bool signalled() const
Was the child signalled?
Definition Process.h:88
bool waitForFinished()
Wait until the underlying process is finished (or dead).
const std::string & lastError() const
Return the last error string if some.
Definition Process.h:97
int readPipe() const
Get the stdout pipe of the process.
Definition Process.h:67
bool kill(int sig)
Send a signal sig to the process.
Error
Errors returned by lastErrorNo().
Definition Process.h:19