| 92 | /**************************************************************************************************/ |
| 93 | |
| 94 | std::string exec(const char* cmd) { |
| 95 | struct pclose_t { |
| 96 | void operator()(std::FILE* p) const { (void)pclose(p); } |
| 97 | }; |
| 98 | std::unique_ptr<std::FILE, pclose_t> pipe{popen(cmd, "r")}; |
| 99 | |
| 100 | if (!pipe) { |
| 101 | throw std::runtime_error("popen() failed!"); |
| 102 | } |
| 103 | |
| 104 | std::array<char, 128> buffer; |
| 105 | std::string result; |
| 106 | while (fgets(buffer.data(), buffer.size(), pipe.get())) { |
| 107 | result += buffer.data(); |
| 108 | } |
| 109 | |
| 110 | return chomp(std::move(result)); |
| 111 | } |
| 112 | |
| 113 | /**************************************************************************************************/ |
| 114 |
no test coverage detected