xerus
a general purpose tensor library
missingFunctions.cpp
Go to the documentation of this file.
1 // Xerus - A General Purpose Tensor Library
2 // Copyright (C) 2014-2017 Benjamin Huber and Sebastian Wolf.
3 //
4 // Xerus is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as published
6 // by the Free Software Foundation, either version 3 of the License,
7 // or (at your option) any later version.
8 //
9 // Xerus is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
13 //
14 // You should have received a copy of the GNU Affero General Public License
15 // along with Xerus. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // For further information on Xerus visit https://libXerus.org
18 // or contact us at contact@libXerus.org.
19 
26 #include <xerus/misc/check.h>
27 #include <xerus/misc/internal.h>
28 
29 namespace xerus {
30  namespace misc {
31  std::string exec(const std::string & _cmd) {
32  FILE* pipe = popen(_cmd.c_str(), "r");
33  REQUIRE(pipe, "could not start " << _cmd);
34  char buffer[128];
35  std::string result = "";
36  while(feof(pipe) == 0) {
37  if(fgets(buffer, 128, pipe) != nullptr) {
38  result += buffer;
39  }
40  }
41  pclose(pipe);
42  return result;
43  }
44 
45  void exec(const std::string & _cmd, const std::string &_stdin) {
46  FILE* pipe = popen(_cmd.c_str(), "w");
47  REQUIRE(pipe, "could not start " << _cmd);
48  fputs(_stdin.c_str(), pipe);
49  pclose(pipe);
50  }
51  } // namespace misc
52 } // namespace xerus
Header file for CHECK and REQUIRE macros.
#define REQUIRE
Definition: internal.h:33
The main namespace of xerus.
Definition: basic.h:37
std::string exec(const std::string &_cmd)
Execute a given command.
Header file for some helper functions.
Header file for comfort functions and macros that should not be exported in the library.