libnick 2025.7.3
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
Nickvision::System::Process Class Reference

A managed process. More...

#include <process.h>

Public Member Functions

 Process (const std::filesystem::path &path, const std::vector< std::string > &args={}, const std::filesystem::path &workingDir={})
 Constructs a Process.
 ~Process ()
 Destructs a Process.
Events::Event< ProcessExitedEventArgs > & exited ()
 Gets the event for when the process has exited.
const std::filesystem::path & getPath () const
 Gets the path of the process.
ProcessState getState () const
 Gets the state of the proicess.
int getExitCode () const
 Gets the exit code of the process.
const std::string & getOutput () const
 Gets the console output of the process.
double getCPUUsage () const
 Gets the percent of the CPU being used by the process.
unsigned long long getRAMUsage () const
 Gets the amount of RAM being used by the process in bytes.
bool start ()
 Starts the process.
bool kill ()
 Kills the process.
bool resume ()
 Resumes the process.
bool pause ()
 Pauses the process.
int waitForExit ()
 Waits for the process to exit.
bool send (const std::string &s)
 Sends text to the process' console.
bool sendCommand (std::string s)
 Sends text to the process' console and adds the return characters.

Detailed Description

A managed process.

Constructor & Destructor Documentation

◆ Process()

Nickvision::System::Process::Process ( const std::filesystem::path & path,
const std::vector< std::string > & args = {},
const std::filesystem::path & workingDir = {} )

Constructs a Process.

Parameters
pathThe path of the process to execute
argsThe arguments to pass to the process
workingDirAn optional working directory to use for a process
Exceptions
std::runtime_errorThrown if the process could not be created

◆ ~Process()

Nickvision::System::Process::~Process ( )

Destructs a Process.

This method will wait for the process to exit if it is still running.

Member Function Documentation

◆ exited()

Events::Event< ProcessExitedEventArgs > & Nickvision::System::Process::exited ( )

Gets the event for when the process has exited.

Returns
The process exited event

◆ getCPUUsage()

double Nickvision::System::Process::getCPUUsage ( ) const

Gets the percent of the CPU being used by the process.

Returns
The CPU usage of the process

◆ getExitCode()

int Nickvision::System::Process::getExitCode ( ) const

Gets the exit code of the process.

Returns
The exit code of the process. -1 if the process has not completed

◆ getOutput()

const std::string & Nickvision::System::Process::getOutput ( ) const

Gets the console output of the process.

Returns
The console output of the process. Empty if the process has not completed

◆ getPath()

const std::filesystem::path & Nickvision::System::Process::getPath ( ) const

Gets the path of the process.

Returns
The path of the process

◆ getRAMUsage()

unsigned long long Nickvision::System::Process::getRAMUsage ( ) const

Gets the amount of RAM being used by the process in bytes.

Returns
The amount of RAM used by the process

◆ getState()

ProcessState Nickvision::System::Process::getState ( ) const

Gets the state of the proicess.

Returns
The state of the process.

◆ kill()

bool Nickvision::System::Process::kill ( )

Kills the process.

Returns
True if the process was killed, else false

◆ pause()

bool Nickvision::System::Process::pause ( )

Pauses the process.

Returns
True if the process was paused, else false

◆ resume()

bool Nickvision::System::Process::resume ( )

Resumes the process.

Returns
True if the process was resumed, else false

◆ send()

bool Nickvision::System::Process::send ( const std::string & s)

Sends text to the process' console.

Parameters
sThe text to send
Returns
True if the text is sent, else false

◆ sendCommand()

bool Nickvision::System::Process::sendCommand ( std::string s)

Sends text to the process' console and adds the return characters.

Parameters
sThe command to send
Returns
True if the command is sent, else false

◆ start()

bool Nickvision::System::Process::start ( )

Starts the process.

Use Process::resume() to start again a paused process.

Returns
True if the process was started, else false

◆ waitForExit()

int Nickvision::System::Process::waitForExit ( )

Waits for the process to exit.

This function will block until the process has exited.

Make sure to call start() / resume() before calling this function.

Returns
The exit code of the process

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