The bst process class is a simple interface to run linux commands.
This is a major refactor of the project cpp-subprocess.
Detailed class documentation can be found here.
Example: Basic usage
#include <iostream>
std::cout << process.getExitCode() << std::endl;
std::cout << process.getStdout() << std::endl;
return 0;
}
A class to handle linux process calls.
Definition: process.hpp:33
void waitToComplete(unsigned int timeout=1000)
Waits for the process to complete. If the process does not complete within the timeout,...
Definition: process.cpp:64
A class to handle linux process calls.
int main()
Definition: visual_tests.cpp:10
$ ./example
0
Hello, World!
Example: Write additional input to stdin
#include <iostream>
process.closeInStream();
process.waitToComplete();
std::cout << process.getExitCode() << std::endl;
std::cout << process.getStdout() << std::endl;
std::cout << process.getStderr() << std::endl;
}
void writeToInStream(const std::string &s)
Definition: process.cpp:34
$ ./example
0
__________
< hi there >
----------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Example: Non-zero command exit codes
#include <iostream>
std::cout << process.getExitCode() << std::endl;
std::cout << process.getStdout() << std::endl;
std::cout << process.getStderr() << std::endl;
return 0;
}
$ ./example
2
ls: cannot access '/nonexistent': No such file or directory
Example: Commands that do not exist
#include <iostream>
std::cout << process.getExitCode() << std::endl;
std::cout << process.getStdout() << std::endl;
std::cout << process.getStderr() << std::endl;
return 0;
}
$ ./example
22
bst_process: execvp() failed: No such file or directory
Example: Command timeout
#include <iostream>
try {
std::cout << e.
what() << std::endl;
}
return 0;
}
Definition: exception.hpp:99
const char * what() const noexcept override
Definition: exception.hpp:110
$ ./example
BST Errno: 14 | process timed out