Start a process, stream its input and output, wait for completion, and control its lifetime.
The string constructor invokes a shell. fromArgs() executes an argument vector directly and searches PATH without shell expansion.
Combine Input, Output, and Error to pipe streams. OutputWithError combines stderr with stdout. Persistent lets the process outlive the command object.
CCommand
Types, constants & data
static constexpr int Output = 0x02;
static constexpr int Error = 0x04;
static constexpr int OutputWithError = 0x08;
static constexpr int Persistent = 0x10;
static constexpr int Zsh = 0x20;
static constexpr int NoStatus = CMax<int>;
static constexpr int ErrorStatus = CMax<int> - 1;
Methods
Immediately launches the command through a shell, using /bin/sh unless Zsh mode is selected. Use fromArgs() for an argument vector without shell expansion.
static CCommand fromArgs(const Strings& arguments, int mode = 0);
Immediately launches an executable from an argument vector, searching PATH as needed. Arguments are passed literally, without shell interpolation or redirection.
Closes the command and waits for termination unless Persistent mode is set. A persistent child may continue running after its wrapper and captured streams are released.
void closeResource() override;
Performs closing cleanup for a nonpersistent command. Persistent mode leaves the child running.
bool readOutput(cstr& out, double timeout);
void readOutput(cstr& out);
Appends output. The untimed overload reads to EOF; the timed form waits for available bytes or EOF and returns false on timeout.
bool matchOutput(const CRegex& regex, Strings& m, double timeout);
Waits until the currently captured standard output matches the entire regex or the timeout in seconds expires. On a match, appends captures to m and consumes that buffered output; otherwise the buffered text remains available.
bool readError(cstr& err, double timeout);
void readError(cstr& err);
Like readOutput(), for captured stderr.
bool matchError(const CRegex& regex, Strings& m, double timeout);
Matches and consumes captured standard error using the same whole-buffer and timeout behavior as matchOutput().
void write(const cstr& in);
Writes all supplied stdin bytes or throws. Captured output continues draining during the write.
Closes stdin, drains both captured streams, and returns the exit status. Captured bytes remain readable.
Returns the child’s process ID while it is tracked as running, or -1 after it has been reaped.
Returns −1 while running. Normal completion returns the exit code; signal termination returns ErrorStatus - signalNumber. NoStatus means no status is available.
Signals the owned process group, or the immediate child when inheriting terminal input. Escalates after one second; false selects asynchronous cleanup.
Sends EOF on the child’s piped stdin.
void setCloseSignal(size_t signalNum);
Sets the signal used by close() to request termination. Closing may escalate if the child does not exit within the grace period.
void signal(size_t signalNum);
Signals the immediate child only. A finished command is a no-op.
bool isPersistent() const;
Reports whether the mode allows the child to outlive this wrapper.
const cstr& command() const;
Borrows the original shell command text, or the executable name supplied as the first argument to fromArgs().