X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fcross.cc;h=171bf2c8100767bb79d8d5b610767c768a44e705;hb=a5be11a965c2c38442e4e069874e7e21b5b43a5c;hp=e3fb22f3999544f69cd0be9be5e40b7e3fb2fb03;hpb=f803bc6d0d1f7e9ede4f11cb564de298ba58daab;p=dcpomatic.git 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 ""; +}