add basic workspace parsing

This commit is contained in:
2025-12-09 17:07:01 +01:00
parent cd3a9e6503
commit fb64f542a9
3 changed files with 109 additions and 12 deletions

View File

@@ -0,0 +1,28 @@
#pragma once
#include <memory>
#include <string>
class SystemHelper
{
public:
static std::string get_command_output(const char *cmd)
{
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, int (*)(FILE *)> pipe(popen(cmd, "r"), pclose);
if (!pipe)
{
throw std::runtime_error("popen() failed!");
}
// Read the output a chunk at a time until the stream ends
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
{
result += buffer.data();
}
return result;
}
};