mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-19 17:38:26 +00:00
[Process] Process Execution Refactor (#2632)
* Swap execute output method * Create "Process" class and move random string to Strings * test * Tweaks
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "process.h"
|
||||
|
||||
std::string Process::execute(const std::string &cmd)
|
||||
{
|
||||
std::shared_ptr<FILE> pipe(popen(cmd.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;
|
||||
}
|
||||
Reference in New Issue
Block a user