ADTF  3.14.3
a_util::process Namespace Reference

Serves as component for interaction with operating system processes. More...

Functions

uint64_t getCurrentProcessId ()
 Get the current process id. More...
 
uint32_t execute (const a_util::filesystem::Path &executable_file, const std::string &arguments, const a_util::filesystem::Path &working_dir, bool wait_for_exit)
 Run an executable as detached process and optionally wait for the application to exit. More...
 
uint32_t execute (const a_util::filesystem::Path &executable_file, const std::string &arguments, const a_util::filesystem::Path &working_dir, std::string &std_out)
 Run an executable and wait for the application to exit. More...
 
uint32_t execute (const a_util::filesystem::Path &executable_file, const std::string &arguments, const a_util::filesystem::Path &working_dir, std::string &std_out, std::string &std_err)
 Start an executable and wait for the application to exit. More...
 
std::string getEnvVar (const std::string &environment_variable_name)
 Retrieve the current value of the environment variable given in environment_variable_name. More...
 
std::string getEnvVar (const std::string &environment_variable_name, const std::string &default_value)
 Retrieve the current value of the environment variable given in environment_variable_name. More...
 
void setEnvVar (const std::string &environment_variable_name, const std::string &environment_variable_value)
 Set an environment variable with a given value to the current process environment areas. More...
 

Detailed Description

Serves as component for interaction with operating system processes.

Function Documentation

◆ execute() [1/3]

uint32_t a_util::process::execute ( const a_util::filesystem::Path executable_file,
const std::string &  arguments,
const a_util::filesystem::Path working_dir,
bool  wait_for_exit 
)

Run an executable as detached process and optionally wait for the application to exit.

Note
The new detached process will use the environment block af the calling process.
Parameters
[in]executable_filePath to executable or command to execute.
[in]argumentsArguments passing to the executable.
[in]working_dirWorking directory. If empty the current working directory is used.
[in]wait_for_exitSpecifies whether the function should wait for the application to close down. only if set to true the return value will be used for applications return value.
Returns
If the wait_for_exit is set to bool exit code of the application only, only -1 if starting failed

◆ execute() [2/3]

uint32_t a_util::process::execute ( const a_util::filesystem::Path executable_file,
const std::string &  arguments,
const a_util::filesystem::Path working_dir,
std::string &  std_out 
)

Run an executable and wait for the application to exit.

Note
The new process will use the environment block af the calling process.
Parameters
[in]executable_filePath to executable or command to execute.
[in]argumentsArguments passing to the executable.
[in]working_dirWorking directory. If empty the current working directory is used.
[in]std_outStandard out of the executed application
Returns
exit code of the application.

◆ execute() [3/3]

uint32_t a_util::process::execute ( const a_util::filesystem::Path executable_file,
const std::string &  arguments,
const a_util::filesystem::Path working_dir,
std::string &  std_out,
std::string &  std_err 
)

Start an executable and wait for the application to exit.

Note
The new process will use the environment block of the calling process.
Parameters
[in]executable_fileexecutable file or command to call.
[in]argumentsArguments passing to the executable.
[in]working_dirWorking directory. If empty the current working directory is used.
[in]std_outStandard out of the program started.
[in]std_errStandard error of the program started.
Returns
exit code of the application.

◆ getCurrentProcessId()

uint64_t a_util::process::getCurrentProcessId ( )

Get the current process id.

Returns
Id of the current process

◆ getEnvVar() [1/2]

std::string a_util::process::getEnvVar ( const std::string &  environment_variable_name)

Retrieve the current value of the environment variable given in environment_variable_name.

Note
The retrieved environment variable is only valid within the current process.
Parameters
[in]environment_variable_nameThe environment variable name to retrieve the value for.
Returns
Value of the environment variable given in environment_variable_name.
Exceptions
std::system_errorIf the environment variable could not be retrieved.
std::runtime_errorIf the environment variable could not be retrieved.

◆ getEnvVar() [2/2]

std::string a_util::process::getEnvVar ( const std::string &  environment_variable_name,
const std::string &  default_value 
)

Retrieve the current value of the environment variable given in environment_variable_name.

If the environment variable is not set the default_value is returned.

Note
The environment variable retrieved is only valid within the current process.
Parameters
[in]environment_variable_nameThe environment variable name to retrieve the value for.
[in]default_valueThe default value if variable is not set.
Returns
Value of environment variable given in environment_variable_name or default_value

◆ setEnvVar()

void a_util::process::setEnvVar ( const std::string &  environment_variable_name,
const std::string &  environment_variable_value 
)

Set an environment variable with a given value to the current process environment areas.

Depending on the underlying process API the environment will be either copied to any child process or not. When using any of the execute() functions, the new process uses a copy of the environment of the calling process.

Note
The environment variable is only valid within the current process.
Parameters
[in]environment_variable_namethe environment variable name to set the value for.
[in]environment_variable_valuethe environment variable value.
Exceptions
std::system_errorIf environment variable could not be set.
std::runtime_errorIf environment variable could not be set.

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Thu Jun 9 2022 by doxygen 1.9.1)