Chris Miles 3e30e78158
[Backups] Fix database dump error reporting (#3175)
* [Backups] Fix database dump error reporting

* Update database_dump_service.cpp
2023-04-04 00:14:23 -05:00

20 lines
447 B
C++

#include <string>
#include <memory>
#include "process.h"
std::string Process::execute(const std::string &cmd)
{
std::string command = fmt::format("{} 2>&1", cmd);
std::shared_ptr<FILE> pipe(popen(command.c_str(), "r"), pclose);
if (!pipe) { return "ERROR"; }
char buffer[128];
std::string result;
while (!feof(pipe.get())) {
if (fgets(buffer, 128, pipe.get()) != nullptr) {
result += buffer;
}
}
return result;
}