Management of processes to launch external programs
Example using the run() method with program and arguments
const auto OutLines = P.stdOutLines();
const auto ErrLines = P.stdErrLines();
Definition: Process.hpp:66
Example using the run() method with fine tuning of command configuration
Cmd.
Args = {
"launch",
"--option=value"};
Env.
Vars[
"VAR1"] =
"value1";
Env.
Vars[
"VAR2"] =
"value2";
P.run();
std::cout << "Exit code: " << P.getExitCode() << std::endl;
Definition: Process.hpp:93
std::string Program
Definition: Process.hpp:97
void setOutErrFiles(const std::string &DirPath, const std::string &NameBase)
std::vector< std::string > Args
Definition: Process.hpp:102
Definition: Process.hpp:73
std::map< std::string, std::string > Vars
Definition: Process.hpp:78
Example using the execute() method
static int execute(const std::string &Program, const std::vector< std::string > &Args={}, const Environment &Env=Environment())
#include <utils/Process.hpp>
◆ Process() [1/2]
openfluid::utils::Process::Process |
( |
const std::string & |
Program, |
|
|
const std::vector< std::string > & |
Args = {} , |
|
|
const Environment & |
Env = Environment() |
|
) |
| |
Constructor using program and arguments to configure the process
- Parameters
-
[in] | Program | Path of the program to execute. |
[in] | Args | Program arguments (empty by default) |
[in] | Env | Execution environment (parent environment by default) |
◆ Process() [2/2]
Constructor using command structure to configure the process
- Parameters
-
[in] | Cmd | Command configuration |
[in] | Env | Execution environment (parent environment by default) |
◆ command()
const Command& openfluid::utils::Process::command |
( |
| ) |
const |
|
inline |
Accesses the command configuration used for the process
- Returns
- The command configuration
◆ environment()
const Environment& openfluid::utils::Process::environment |
( |
| ) |
const |
|
inline |
Accesses the execution environment used for the process
- Returns
- The execution environment
◆ execute() [1/2]
Executes a process using the given command configuration and execution environment
- Parameters
-
[in] | Cmd | Command configuration |
[in] | Env | Execution environment (parent environment by default) |
◆ execute() [2/2]
static int openfluid::utils::Process::execute |
( |
const std::string & |
Program, |
|
|
const std::vector< std::string > & |
Args = {} , |
|
|
const Environment & |
Env = Environment() |
|
) |
| |
|
static |
Executes a process using the given program, arguments and execution environment
- Parameters
-
[in] | Program | Path of the program to execute. |
[in] | Args | Program arguments (empty by default) |
[in] | Env | Execution environment (parent environment by default) |
◆ getErrorMessage()
std::string openfluid::utils::Process::getErrorMessage |
( |
| ) |
const |
|
inline |
Gets the error message in case of execution problem
- Returns
- The error message. Do not confuse with exit code
◆ getExitCode()
int openfluid::utils::Process::getExitCode |
( |
| ) |
const |
|
inline |
Gets the exit code returned by the executed program when finished
- Returns
- The exit code
◆ run()
bool openfluid::utils::Process::run |
( |
| ) |
|
Runs the process
- Returns
- true if the process has been run, false otherwise. Do not confuse with exit code
◆ stdErrLines()
const std::vector<std::string>& openfluid::utils::Process::stdErrLines |
( |
| ) |
const |
|
inline |
Accesses to the lines of the standard error stream once the process have run. These lines set is empty if the redirection of the standard error stream has been enabled
- Returns
- The error stream lines
◆ stdOutLines()
const std::vector<std::string>& openfluid::utils::Process::stdOutLines |
( |
| ) |
const |
|
inline |
Accesses to the lines of the standard output stream once the process have run. These lines set is empty if the redirection of the standard output stream has been enabled
- Returns
- The output stream lines
◆ system() [1/2]
Executes a process using the given command configuration and execution environment with default standard i/o (stdout,stderr,stdin). It works as std::system with more options.
- Parameters
-
[in] | Cmd | Command configuration |
[in] | Env | Execution environment (parent environment by default) |
◆ system() [2/2]
static int openfluid::utils::Process::system |
( |
const std::string & |
Program, |
|
|
const std::vector< std::string > & |
Args = {} , |
|
|
const Environment & |
Env = Environment() |
|
) |
| |
|
static |
Executes a process using the given program, arguments and execution environment with default standard i/o (stdout,stderr,stdin). It works as std::system with more options.
- Parameters
-
[in] | Program | Path of the program to execute. |
[in] | Args | Program arguments (empty by default) |
[in] | Env | Execution environment (parent environment by default) |
The documentation for this class was generated from the following file: