#pragma once #include #include #include #include #include class CommandHelper { public: static std::string exec(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!"); } while (fgets(buffer.data(), static_cast(buffer.size()), pipe.get()) != nullptr) { result += buffer.data(); } return result; } static void execNoOutput(std::string cmd) { std::string command = cmd + " > /dev/null 2>&1"; int ret = std::system(command.c_str()); if (ret != 0) { throw std::runtime_error("Command failed with return code: " + std::to_string(ret)); } } };