How to execute a command and get return code stdout and stderr of command in C++
问题 Given the following answer (first c++11 answer): How to execute a command and get output of command within C++ using POSIX? Here is the implementation for your convinience: #include <cstdio> #include <iostream> #include <memory> #include <stdexcept> #include <string> #include <array> std::string exec(const char* cmd) { std::array<char, 128> buffer; std::string result; std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose); if (!pipe) throw std::runtime_error("popen() failed!"); while (!feof(pipe