41 string strErr(
"Failed to create pipe. Errno: ");
42 strErr += to_string(errno);
43 throw runtime_error(strErr);
87 Spawn::Spawn(
const char*
const argv[],
bool fUseStdErr,
bool fWithPath,
const char*
const envp[]): m_iChildPid(-1), m_pWriteBuf(NULL), m_pReadBuf(NULL), stdin(NULL), stdout(NULL), m_WritePipe(), m_ReadPipe()
91 throw runtime_error(
"Failed to start child process");
110 iRes = ::execvpe(argv[0], const_cast<char* const*>(argv), const_cast<char* const*>(envp));
112 iRes = ::execvp(argv[0], const_cast<char* const*>(argv));
117 iRes = ::execve(argv[0], const_cast<char* const*>(argv), const_cast<char* const*>(envp));
119 iRes = ::execv(argv[0], const_cast<char* const*>(argv));
125 cout <<
"Error: Failed to launch program \"" << argv[0] <<
"\" Error: " << to_string(errno) << endl;
127 cerr <<
"Error: Failed to launch program \"" << argv[0] <<
"\" Error: " << to_string(errno) << endl;
138 stdin.rdbuf(m_pWriteBuf);
178 pid_t iTerminatedPid(::waitpid(
m_iChildPid, &iStatus, WUNTRACED | WCONTINUED));
179 if (iTerminatedPid == -1)
181 iStatus = EXIT_FAILURE;
184 }
while (!WIFEXITED(iStatus) && !WIFSIGNALED(iStatus));
__gnu_cxx::stdio_filebuf< char > * m_pReadBuf
int wait()
Wait until child process has terminated.
const int writeFd() const
Spawn(const char *const argv[], bool fUseStdErr=false, bool fWithPath=false, const char *const envp[]=NULL)
Spawns a child process.
__gnu_cxx::stdio_filebuf< char > * m_pWriteBuf