From 89737ad005f4c066234a5282a1a46eb68b2c1ace Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 3 Dec 2019 20:21:09 +0100 Subject: cpp mode --- src/jo_exec.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/jo_exec.cpp (limited to 'src/jo_exec.cpp') 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 + +string +jo_exec(const char* cmd) { + array buffer; + string result; + unique_ptr 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; +} -- cgit v1.2.3