#include "ob/sys_command.hh" #include #include #include namespace OB { int exec(std::string& result, std::string const& command) { const char* cmd {command.c_str()}; int const buf_len {1024}; std::array buf; std::shared_ptr pipe(popen(cmd, "r"), pclose); if (!pipe) { return -1; } while (!feof(pipe.get())) { if (fgets(buf.data(), buf_len, pipe.get()) != nullptr) { result += buf.data(); } } return 0; } } // namespace OB