1 #include "hmbdc/Copyright.hpp"
4 #include "hmbdc/Exception.hpp"
15 namespace hmbdc {
namespace os {
29 ,
bool captureStderr =
false);
62 auto s = write(
exeStdinFd, input, strlen(input));
63 if ((
size_t)s != strlen(input)) {
64 HMBDC_THROW(std::runtime_error,
"write failed, bytes written=" << s);
69 ExecutionIo& operator << (std::string
const& input) {
70 auto s = write(
exeStdinFd, input.c_str(), input.size());
71 if ((
size_t)s != input.size()) {
72 HMBDC_THROW(std::runtime_error,
"write failed, bytes written=" << s);
79 auto l = std::find(buf_, buf_ + bufLen_,
'\n');
81 if (l == buf_ +
sizeof(buf_)) l--;
82 if (l != buf_ + bufLen_) {
83 output = std::string(buf_, l + 1);
84 bufLen_ -= output.size();
85 memmove(buf_, l + 1, bufLen_);
88 int s = read(
exeStdoutFd, buf_ + bufLen_,
sizeof(buf_) - bufLen_);
96 output = std::string(buf, s);
ExecutionIo(const char *const argv[], bool captureStderr=false)
execute a program as a child and capture its stdin stdout and/or stderr
pid_t exePid
process id of the started child process
Definition: ExecutionIo.hpp:54
int exeStderrFd
if captured, child stderr fd, use read on it - not write
Definition: ExecutionIo.hpp:49
int exeStdoutFd
child stdout fd, use read on it - not write
Definition: ExecutionIo.hpp:43
execute a program as a child and capture its stdin stdout and/or stderr
Definition: ExecutionIo.hpp:20
int exeStdinFd
child stdin fd, use write on it - not read
Definition: ExecutionIo.hpp:37