9 std::function<
void(
int)> _pclose_handler,
10 bool _combine_stdout_stderr)
11 : m_popen_handler(_popen_handler),
12 m_pclose_handler(_pclose_handler),
13 m_combine_stdout_stderr(_combine_stdout_stderr) {}
33 while (fgets(path, PATH_MAX, fp) !=
nullptr) {
57 throw std::runtime_error(
"Error: popen failed.");
65 throw std::runtime_error(
"Error: pclose failed.");
std::string gets() const
Returns the stdout resulting from the last popen call.
Popen(std::function< void(FILE *)> _popen_handler=Popen::default_popen_handler, std::function< void(int)> _pclose_handler=Popen::default_pclose_handler, bool _combine_stdout_stderr=true)
Construct a Popen object.
static void default_pclose_handler(int status)
Default pclose error handler throws std::runtime_error if pclose failed.
void popen(std::string _command)
Execute popen for a given command.
void print(std::ostream &sout) const
Print the last command executed and the resulting stdout.
std::function< void(int)> m_pclose_handler
int exit_code() const
Returns pclose(fp)/256.
static void default_popen_handler(FILE *fp)
Default popen error handler throws std::runtime_error if popen failed.
std::function< void(FILE *)> m_popen_handler
bool m_combine_stdout_stderr