aboutsummaryrefslogtreecommitdiffstats
path: root/src/jo_exec.cpp
blob: a97012c6bd103f569f8f4ebe7c2f2e187b456a2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <jo_lowbat.hpp>

string
jo_exec(const char* cmd) {
    array<char, 128> buffer;
    string result;
    unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
    if (!pipe) {
        throw runtime_error("popen() failed!");
    }
    while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
        result += buffer.data();
    }
    return result;
}