5 #ifndef LODESTAR_EXECUTECOMMAND_HPP
6 #define LODESTAR_EXECUTECOMMAND_HPP
19 static bool commandExists(const ::std::string &cmd);
21 template<
unsigned int NBufferSize = 512>
22 static ::std::string getStdout(const ::std::string &cmd)
24 static std::array<char, NBufferSize> buffer{};
26 std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(),
"r"), pclose);
28 throw std::runtime_error(
"popen() failed!");
30 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr) {
31 result += buffer.data();
40 #endif //LODESTAR_EXECUTECOMMAND_HPP