Maki
Formally verfied low-code orchestration
Loading...
Searching...
No Matches
ProcessRunner Class Reference

Class for running processes with customizable environment and options. More...

#include <process_runner.h>

Inheritance diagram for ProcessRunner:

Public Member Functions

 ProcessRunner (QObject *parent=nullptr)
 Constructs a new ProcessRunner object.
void addEnvVariable (const QString &key, const QString &value)
 Adds an environment variable to the process.
void removeEnvVariable (const QString &key, const QString &value)
 Removes an environment variable from the process.
void setCwd (const QString &path)
 Sets the current working directory for the process.
void setTimeout (int ms)
 Sets the timeout for the process in milliseconds.
int runSync (const QString &cmd, QString &result)
 Runs a command synchronously and returns the result.
void runAsync (const QString &cmd, FinshedCallback finishedCb, LogCallback stdoutCb=nullptr, LogCallback stderrCb=nullptr)
 Runs a command asynchronously with callbacks for finished and logging.

Static Public Member Functions

static int ExecuteSync (const QString &cmd, QString &result)
 Runs a command synchronously and returns the result.
static void ExecuteAsync (const QString &cmd, QObject *parent, FinshedCallback finishedCb, LogCallback stdoutCb=nullptr, LogCallback stderrCb=nullptr)
 Runs a command asynchronously with callbacks for finished and logging.

Private Attributes

QString mCwd
 Environment variables for the process.
int mTimeout
 Current working directory for the process.

Detailed Description

Class for running processes with customizable environment and options.

Constructor & Destructor Documentation

◆ ProcessRunner()

ProcessRunner::ProcessRunner ( QObject * parent = nullptr)

Constructs a new ProcessRunner object.

Parameters
parentPointer to the parent QObject, if any.

Member Function Documentation

◆ addEnvVariable()

void ProcessRunner::addEnvVariable ( const QString & key,
const QString & value )

Adds an environment variable to the process.

Parameters
keyThe name of the environment variable.
valueThe value of the environment variable.

◆ ExecuteAsync()

void ProcessRunner::ExecuteAsync ( const QString & cmd,
QObject * parent,
FinshedCallback finishedCb,
LogCallback stdoutCb = nullptr,
LogCallback stderrCb = nullptr )
static

Runs a command asynchronously with callbacks for finished and logging.

Parameters
cmdThe command to run.
parentPointer to the parent QObject.
finishedCbCallback function called when the process finishes.
stdoutCbOptional callback function for standard output logging.
stderrCbOptional callback function for standard error logging.

◆ ExecuteSync()

int ProcessRunner::ExecuteSync ( const QString & cmd,
QString & result )
static

Runs a command synchronously and returns the result.

Parameters
cmdThe command to run.
resultReference to a string where the output will be stored.
Returns
int The exit code of the process.

◆ removeEnvVariable()

void ProcessRunner::removeEnvVariable ( const QString & key,
const QString & value )

Removes an environment variable from the process.

Parameters
keyThe name of the environment variable to remove.
valueThe value of the environment variable to remove.

◆ runAsync()

void ProcessRunner::runAsync ( const QString & cmd,
FinshedCallback finishedCb,
LogCallback stdoutCb = nullptr,
LogCallback stderrCb = nullptr )

Runs a command asynchronously with callbacks for finished and logging.

Parameters
cmdThe command to run.
finishedCbCallback function called when the process finishes.
stdoutCbOptional callback function for standard output logging.
stderrCbOptional callback function for standard error logging.

◆ runSync()

int ProcessRunner::runSync ( const QString & cmd,
QString & result )

Runs a command synchronously and returns the result.

Parameters
cmdThe command to run.
resultReference to a string where the output will be stored.
Returns
int The exit code of the process.

◆ setCwd()

void ProcessRunner::setCwd ( const QString & path)

Sets the current working directory for the process.

Parameters
pathThe path to set as the current working directory.

◆ setTimeout()

void ProcessRunner::setTimeout ( int ms)

Sets the timeout for the process in milliseconds.

Parameters
msThe timeout value in milliseconds.

The documentation for this class was generated from the following files:
  • /__w/maki/maki/app/common/process_runner.h
  • /__w/maki/maki/app/common/process_runner.cpp