7 std::array<char, 128> buffer;
10 FILE* pipe = popen((command +
" 2>&1").c_str(),
"r");
12 throw std::runtime_error(
"Error while opening command pipe for: " + command);
15 while (fgets(buffer.data(), buffer.size(), pipe) !=
nullptr) {
16 result += buffer.data();
19 const int status = pclose(pipe);
20 const bool ok = WIFEXITED(status) && WEXITSTATUS(status) == 0;
23 std::string message =
"Command failed:\n" + command +
"\n";
24 if (!result.empty()) {
25 message +=
"Output:\n" + result;
27 throw std::runtime_error(message);