#pragma once #include #include class SystemHelper { public: static std::string get_command_output(const char *cmd) { std::array buffer; std::string result; std::unique_ptr pipe(popen(cmd, "r"), pclose); if (!pipe) { throw std::runtime_error("popen() failed!"); } // Read the output a chunk at a time until the stream ends while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { result += buffer.data(); } return result; } };