Compare View

switch
from
...
to
 
Commits (4)
include/cbutils.h
... ... @@ -16,6 +16,7 @@
16 16 #include <algorithm>
17 17 #include <boost/algorithm/string.hpp>
18 18 #include <cstddef>
  19 +#include <cstdlib>
19 20 #include <fstream>
20 21 #include <stdexcept>
21 22 #include <string>
... ... @@ -51,6 +52,20 @@ std::string join(const std::vector&lt;std::string&gt;&amp; vos, char sep=&#39; &#39;)
51 52 return ss.str();
52 53 }
53 54 } //end ns string
  55 +// ----------------- System calls ----------------------------------------------
  56 +namespace system{
  57 +// Runs the command sending it to the OS and returns a string wit its output
  58 +std::string call(const std::string& command)
  59 +{
  60 + std::string tmp_filename{std::tmpnam(nullptr)};
  61 + std::stringstream command_redirect{command+" > "+tmp_filename};
  62 + std::system(command_redirect.str().c_str());
  63 + std::stringstream command_output;
  64 + command_output << std::ifstream(tmp_filename).rdbuf();
  65 + std::remove(tmp_filename.c_str());
  66 + return command_output.str();
  67 +}
  68 +} //end ns system
54 69 // ----------------- File IO ---------------------------------------------------
55 70 namespace file
56 71 {
... ...