[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:
Chris Miles
2022-12-11 13:08:55 -06:00
committed by GitHub
parent 70719852d6
commit f5126222c2
8 changed files with 73 additions and 83 deletions
+18
View File
@@ -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;
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef EQEMU_PROCESS_H
#define EQEMU_PROCESS_H
#include "../strings.h"
#include <cstdio>
#if _WIN32
#define popen _popen
#define pclose _pclose
#endif
class Process {
public:
static std::string execute(const std::string &cmd);
};
#endif //EQEMU_PROCESS_H