Subprocess execution with pipe-based I/O. More...
#include <process.h>


Public Types | |
| enum | State { NotRunning = 0 , Starting , Running } |
| Process state. More... | |
Public Types inherited from ObjectBase | |
| using | SlotVariantFunc = std::function< void(const VariantList &)> |
| Function type for invoking a slot with a list of Variants. | |
Public Member Functions | |
| Process (const Process &)=delete | |
| Deleted copy constructor (non-copyable). | |
| Process & | operator= (const Process &)=delete |
| Deleted copy assignment operator (non-copyable). | |
| Process (ObjectBase *parent=nullptr) | |
| Default constructor. | |
| ~Process () | |
| Destructor. Kills the child process if still running. | |
| const String & | program () const |
| Returns the program path. | |
| void | setProgram (const String &program) |
| Sets the program to execute. | |
| const List< String > & | arguments () const |
| Returns the argument list. | |
| void | setArguments (const List< String > &args) |
| Sets the argument list for the subprocess. | |
| const FilePath & | workingDirectory () const |
| Returns the working directory for the subprocess. | |
| void | setWorkingDirectory (const FilePath &dir) |
| Sets the working directory for the subprocess. | |
| const Map< String, String > & | environment () const |
| Returns the environment variables for the subprocess. | |
| void | setEnvironment (const Map< String, String > &env) |
| Sets the environment variables for the subprocess. | |
| Error | start () |
| Starts the subprocess using the previously set program and arguments. | |
| Error | start (const String &program, const List< String > &args) |
| Convenience: sets program and arguments, then starts. | |
| Error | waitForStarted (unsigned int timeoutMs=0) |
| Blocks until the subprocess has started or the timeout expires. | |
| Error | waitForFinished (unsigned int timeoutMs=0) |
| Blocks until the subprocess has finished or the timeout expires. | |
| int | exitCode () const |
| Returns the exit code of the finished process. | |
| bool | isRunning () const |
| Returns true if the subprocess is currently running. | |
| State | state () const |
| Returns the current process state. | |
| pid_t | pid () const |
| Returns the child process ID. | |
| void | kill () |
| Sends SIGKILL to the child process. | |
| void | terminate () |
| Sends SIGTERM to the child process. | |
| ssize_t | writeToStdin (const void *buf, size_t bytes) |
| Writes data to the child's stdin pipe. | |
| Buffer | readAllStdout () |
| Reads all available data from the child's stdout. | |
| Buffer | readAllStderr () |
| Reads all available data from the child's stderr. | |
| void | closeWriteChannel () |
| Closes the write end of the stdin pipe. | |
| PROMEKI_SIGNAL (started) | |
| Emitted when the subprocess starts running. | |
| PROMEKI_SIGNAL (finished, int) | |
| Emitted when the subprocess finishes (carries the exit code). | |
| PROMEKI_SIGNAL (readyReadStdout) | |
| Emitted when data is available on the child's stdout. | |
| PROMEKI_SIGNAL (readyReadStderr) | |
| Emitted when data is available on the child's stderr. | |
| PROMEKI_SIGNAL (errorOccurred, Error) | |
| Emitted when an error occurs during subprocess execution. | |
Public Member Functions inherited from ObjectBase | |
| ObjectBase (ObjectBase *p=nullptr) | |
| Default ObjectBase constructor. | |
| virtual | ~ObjectBase () |
| Destructor. Emits aboutToDestroy, detaches from parent, and destroys children. | |
| ObjectBase * | parent () const |
| Returns the parent object, if one. nullptr if none. | |
| void | setParent (ObjectBase *p) |
| Sets the parent of this object. If the object already has a parent, it will be removed as a child from the old parent and added as a child to the new one. | |
| const ObjectBaseList & | childList () const |
| Returns a list of children of this object. | |
| template<typename... Args> | |
| int | registerSlot (Slot< Args... > *slot) |
| Registers a slot with this object and assigns it an ID. | |
| EventLoop * | eventLoop () const |
| Returns the EventLoop this object is affiliated with. | |
| void | moveToThread (EventLoop *loop) |
| Changes the EventLoop affinity of this object. | |
| int | startTimer (unsigned int intervalMs, bool singleShot=false) |
| Starts a timer on this object's EventLoop. | |
| void | stopTimer (int timerId) |
| Stops a timer previously started with startTimer(). | |
| template<typename... Args> | |
| PROMEKI_NAMESPACE_BEGIN void | connect (Signal< Args... > *signal, Slot< Args... > *slot) |
Additional Inherited Members | |
Static Public Member Functions inherited from ObjectBase | |
| static const MetaInfo & | metaInfo () |
| Returns the MetaInfo for the ObjectBase class. | |
| template<typename... Args> | |
| static void | connect (Signal< Args... > *signal, Slot< Args... > *slot) |
| connects a signal and slot together. This function assumes both the signal and slot exist in a ObjectBase or derived object | |
Public Attributes inherited from ObjectBase | |
| Signal< ObjectBase * > | aboutToDestroySignal = Signal< ObjectBase * >(this, aboutToDestroySignalName) |
Static Public Attributes inherited from ObjectBase | |
| static constexpr const char * | aboutToDestroySignalName = PROMEKI_STRINGIFY( aboutToDestroy ) "(" PROMEKI_STRINGIFY_ARGS( ObjectBase * ) ")" |
| static SignalMeta | aboutToDestroySignalMeta = SignalMeta(metaInfo(), aboutToDestroySignalName) |
Protected Member Functions inherited from ObjectBase | |
| ObjectBase * | signalSender () |
| Returns the ObjectBase that emitted the signal currently being handled. | |
| virtual void | event (Event *e) |
| Called by EventLoop to deliver events to this object. | |
| virtual void | timerEvent (TimerEvent *e) |
| Called when a timer fires for this object. | |
Subprocess execution with pipe-based I/O.
Wraps subprocess creation and management using pipe() + fork() + exec() on POSIX platforms. Provides access to the child process's stdin, stdout, and stderr via pipe-based I/O methods.
On unsupported platforms (e.g. WASM/Emscripten), start() returns Error::NotSupported.
| Process::Process | ( | ObjectBase * | parent = nullptr | ) |
Default constructor.
| parent | The parent object, or nullptr. |
Returns the argument list.
| void Process::closeWriteChannel | ( | ) |
Closes the write end of the stdin pipe.
Signals EOF to the child's stdin.
Returns the environment variables for the subprocess.
|
inline |
Returns the exit code of the finished process.
Only valid after the process has finished.
|
inline |
Returns true if the subprocess is currently running.
|
inline |
Returns the child process ID.
Only valid while the process is running or has recently finished.
Returns the program path.
| Process::PROMEKI_SIGNAL | ( | errorOccurred | , |
| Error | |||
| ) |
Emitted when an error occurs during subprocess execution.
| Process::PROMEKI_SIGNAL | ( | finished | , |
| int | |||
| ) |
Emitted when the subprocess finishes (carries the exit code).
| Process::PROMEKI_SIGNAL | ( | readyReadStderr | ) |
Emitted when data is available on the child's stderr.
| Process::PROMEKI_SIGNAL | ( | readyReadStdout | ) |
Emitted when data is available on the child's stdout.
| Buffer Process::readAllStderr | ( | ) |
Reads all available data from the child's stderr.
| Buffer Process::readAllStdout | ( | ) |
Reads all available data from the child's stdout.
Sets the argument list for the subprocess.
| args | The arguments to pass to the program. |
Sets the environment variables for the subprocess.
If empty, the child inherits the parent's environment.
| env | A map of environment variable names to values. |
Sets the program to execute.
| program | Path to the executable. |
Sets the working directory for the subprocess.
If empty, the child inherits the parent's working directory.
| dir | The directory to run the subprocess in. |
| Error Process::start | ( | ) |
Starts the subprocess using the previously set program and arguments.
Convenience: sets program and arguments, then starts.
| program | Path to the executable. |
| args | The arguments to pass to the program. |
|
inline |
Returns the current process state.
Blocks until the subprocess has finished or the timeout expires.
Reads any remaining stdout/stderr data and collects the exit status.
| timeoutMs | Maximum time to wait in milliseconds (0 = wait indefinitely). |
Blocks until the subprocess has started or the timeout expires.
| timeoutMs | Maximum time to wait in milliseconds (0 = wait indefinitely). |
Returns the working directory for the subprocess.
Writes data to the child's stdin pipe.
| buf | Pointer to the data to write. |
| bytes | Number of bytes to write. |