summaryrefslogtreecommitdiff
path: root/src/lib/cross.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/cross.cc')
-rw-r--r--src/lib/cross.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib/cross.cc b/src/lib/cross.cc
index e3fb22f39..171bf2c81 100644
--- a/src/lib/cross.cc
+++ b/src/lib/cross.cc
@@ -474,3 +474,30 @@ home_directory ()
return boost::filesystem::path(getenv("HOMEDRIVE")) / boost::filesystem::path(getenv("HOMEPATH"));
#endif
}
+
+string
+command_and_read (string cmd)
+{
+#ifdef DCPOMATIC_LINUX
+ FILE* pipe = popen (cmd.c_str(), "r");
+ if (!pipe) {
+ throw runtime_error ("popen failed");
+ }
+
+ string result;
+ char buffer[128];
+ try {
+ while (fgets(buffer, sizeof(buffer), pipe)) {
+ result += buffer;
+ }
+ } catch (...) {
+ pclose (pipe);
+ throw;
+ }
+
+ pclose (pipe);
+ return result;
+#endif
+
+ return "";
+}