diff options
| author | Vaxry <vaxry@vaxry.net> | 2024-11-09 17:11:38 +0000 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2024-11-09 17:14:25 +0000 |
| commit | a8ff3a452c1c445d24bdd9e7e4fcd66c8ef2a147 (patch) | |
| tree | 7bd6e4e4d41892b1e77ba4d967191313cbf77a21 /src/helpers/MiscFunctions.cpp | |
| parent | dca75db127fedc58fc85ae0e6e47162e3d5d16f9 (diff) | |
core: move to os/Process from hyprutils
nix bump too
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
| -rw-r--r-- | src/helpers/MiscFunctions.cpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 878f5ca1..75154796 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -17,7 +17,9 @@ #include <execinfo.h> #endif #include <hyprutils/string/String.hpp> +#include <hyprutils/os/Process.hpp> using namespace Hyprutils::String; +using namespace Hyprutils::OS; #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) #include <sys/sysctl.h> @@ -583,18 +585,12 @@ float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Ve // Execute a shell command and get the output std::string execAndGet(const char* cmd) { - std::array<char, 128> buffer; - std::string result; - using PcloseType = int (*)(FILE*); - const std::unique_ptr<FILE, PcloseType> pipe(popen(cmd, "r"), static_cast<PcloseType>(pclose)); - if (!pipe) { - Debug::log(ERR, "execAndGet: failed in pipe"); - return ""; - } - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { - result += buffer.data(); - } - return result; + CProcess proc("/bin/sh", {cmd}); + + if (!proc.runSync()) + return "error"; + + return proc.stdOut(); } void logSystemInfo() { |
