aboutsummaryrefslogtreecommitdiffstats
path: root/src/jo_exec.cpp
diff options
context:
space:
mode:
authorJoe <bousset.rudy@gmail.com>2019-12-03 20:21:09 +0100
committerJoe <bousset.rudy@gmail.com>2019-12-03 20:21:09 +0100
commit89737ad005f4c066234a5282a1a46eb68b2c1ace (patch)
tree7b521091227050c84dca220715e20bf1347c39d3 /src/jo_exec.cpp
parentREADME update (diff)
downloadlowbat-gnu-89737ad005f4c066234a5282a1a46eb68b2c1ace.tar.gz
lowbat-gnu-89737ad005f4c066234a5282a1a46eb68b2c1ace.tar.bz2
lowbat-gnu-89737ad005f4c066234a5282a1a46eb68b2c1ace.tar.xz
lowbat-gnu-89737ad005f4c066234a5282a1a46eb68b2c1ace.tar.zst
lowbat-gnu-89737ad005f4c066234a5282a1a46eb68b2c1ace.zip
cpp mode
Diffstat (limited to '')
-rw-r--r--src/jo_exec.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/jo_exec.cpp b/src/jo_exec.cpp
new file mode 100644
index 0000000..a97012c
--- /dev/null
+++ b/src/jo_exec.cpp
@@ -0,0 +1,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;
+}