SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
execute.h
Go to the documentation of this file.
1 /**
2  * @file Execute.h
3  * @author Gereon Kremer <gereon.kremer@cs.rwth-aachen.de>
4  */
5 
6 #pragma once
7 
8 namespace benchmax {
9 
10 /**
11  * Runs an external program from some command line and records the output to stdout.
12  * Prints the program output and records it at the same time if print_to_stdout is set to true.
13  * @param commandline Program to execute.
14  * @param stdout Standard output.
15  * @param print_to_stdout Also print if true.
16  * @return Exit code of the program.
17  */
18 inline int call_program(const std::string& commandline, std::string& stdout, bool print_to_stdout = false) {
19  FILE* pipe = popen(commandline.c_str(), "r");
20  char buf[255];
21  while (!feof(pipe)) {
22  if (fgets(buf, sizeof(buf), pipe) != nullptr) {
23  stdout += buf;
24  if (print_to_stdout) {
25  std::cout << buf;
26  }
27  }
28  }
29  return pclose(pipe);
30 }
31 
32 }
int call_program(const std::string &commandline, std::string &stdout, bool print_to_stdout=false)
Runs an external program from some command line and records the output to stdout.
Definition: execute.h:18