RADLib
RADical C++ application framework
RADCore::RADProcess Class Reference

Child process helper for stdout/stderr capture. More...

#include <RADCore.h>

+ Inheritance diagram for RADCore::RADProcess:
+ Collaboration diagram for RADCore::RADProcess:

Public Member Functions

 RADProcess ()
 Creates a non-running process. More...
 
 ~RADProcess () override
 Kills or cleans up the process if needed. More...
 
bool start (const std::string &program, const std::vector< std::string > &arguments={})
 Starts program with arguments. More...
 
bool waitForFinished (int timeoutMs=-1)
 Waits for process exit; timeoutMs < 0 waits indefinitely. More...
 
void kill ()
 Sends a kill request to the process. More...
 
ProcessState state () const
 Returns process state. More...
 
int exitCode () const
 Returns exit code after finish. More...
 
std::string readAllStandardOutput () const
 Returns captured stdout. More...
 
std::string readAllStandardError () const
 Returns captured stderr. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Public Attributes

RADCore::Event< void() > started
 Raised when the child process starts. More...
 
RADCore::Event< void(int) > finished
 Raised with exit code when the child exits. More...
 
RADCore::Event< void(std::string) > errorOccurred
 Raised when process start/wait/read fails. More...
 

Detailed Description

Child process helper for stdout/stderr capture.

Constructor & Destructor Documentation

◆ RADProcess()

RADCore::RADProcess::RADProcess ( )

Creates a non-running process.

◆ ~RADProcess()

RADCore::RADProcess::~RADProcess ( )
override

Kills or cleans up the process if needed.

Member Function Documentation

◆ exitCode()

int RADCore::RADProcess::exitCode ( ) const

Returns exit code after finish.

◆ kill()

void RADCore::RADProcess::kill ( )

Sends a kill request to the process.

◆ readAllStandardError()

std::string RADCore::RADProcess::readAllStandardError ( ) const

Returns captured stderr.

◆ readAllStandardOutput()

std::string RADCore::RADProcess::readAllStandardOutput ( ) const

Returns captured stdout.

◆ start()

bool RADCore::RADProcess::start ( const std::string &  program,
const std::vector< std::string > &  arguments = {} 
)

Starts program with arguments.

◆ state()

ProcessState RADCore::RADProcess::state ( ) const

Returns process state.

◆ waitForFinished()

bool RADCore::RADProcess::waitForFinished ( int  timeoutMs = -1)

Waits for process exit; timeoutMs < 0 waits indefinitely.

Member Data Documentation

◆ errorOccurred

RADCore::Event<void (std::string) > RADCore::RADProcess::errorOccurred

Raised when process start/wait/read fails.

◆ finished

RADCore::Event<void (int) > RADCore::RADProcess::finished

Raised with exit code when the child exits.

◆ started

RADCore::Event<void () > RADCore::RADProcess::started

Raised when the child process starts.


The documentation for this class was generated from the following file: