Implement the mecanism to spawn a program.
More...
#include <Spawn.hpp>
|
| Spawn () |
|
| ~Spawn () override=default |
|
void | execute (const std::string &args) override |
| Spawn a program using the command arguments Double fork to avoid zombie processes Parse the command arguments to get the program name and its arguments use of execvp to execute the command so it will search the bin using PATH throw an exception if the command fails. More...
|
|
Implement the mecanism to spawn a program.
◆ Spawn()
◆ ~Spawn()
◆ execute()
void Spawn::execute |
( |
const std::string & |
args | ) |
|
|
overridevirtual |
Spawn a program using the command arguments Double fork to avoid zombie processes Parse the command arguments to get the program name and its arguments use of execvp to execute the command so it will search the bin using PATH throw an exception if the command fails.
- Parameters
-
args | the first word separated by a space is the binary name, the rest is the arguments |
Implements CommandBase.
38 std::istringstream iss(args);
41 std::vector<const char*> argv;
42 argv.push_back(command.c_str());
45 argv.push_back(arg.c_str());
47 argv.push_back(
nullptr);
50 throw std::runtime_error(
"Fork failed: " + std::string(strerror(errno)));
51 }
else if (pid == 0) {
52 pid_t pid_inner = fork();
55 }
else if (pid_inner == 0) {
56 execvp(command.c_str(),
const_cast<char* const*
>(argv.data()));
65 waitpid(pid,
nullptr, 0);
@ L_ERROR
Definition: Logger.hpp:51
@ L_INFO
Definition: Logger.hpp:49
virtual void Log(const std::string &message, LogLevel level) const
Log a message This method logs a message to the log file or stream. The message is only logged if the...
Definition: Logger.cpp:73
static Logger * GetInstance()
Get the Logger object.
Definition: Logger.cpp:41
References Logger::GetInstance(), L_ERROR, L_INFO, and Logger::Log().
The documentation for this class was generated from the following files: