Outsourced command execution to service

This commit is contained in:
2025-06-10 16:46:58 +02:00
parent 343b6aadf7
commit 4b8c8c355f
3 changed files with 42 additions and 26 deletions

22
src/ShellService.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include "../include/ShellService.h"
std::string ShellService::exec(const std::string& command) {
char buffer[128];
std::string result = "";
FILE* pipe = popen(command.c_str(), "r");
if (!pipe) {
return "popen failed";
}
while (fgets(buffer, sizeof(buffer), pipe) != NULL) {
result += buffer;
}
int status = pclose(pipe);
if (status == -1) {
return "Error closing pipe";
}
return result;
};