cross platform subprocess library for c++ similar to design of python subprocess. See subprocess documentation for further documentation.
supports
- very python like style of subprocess. With very nice syntax for c++20.
- Connect output of process A to input of process B. However not pretty API for this.
Shakey elements
- The os error level exceptions is still changing. I'm thinking of having an OSError subclass to abstract the OS differences.
requirements
- c++17
- linked with support for threading, filesystem
Integration
Adhoc
- copy files in src/cpp to your project.
- add the top folder as include.
- make sure cpp files are compiled.
- add
#include <subprocess.hpp>
to start using in source files.
<a href="https://bitbucket.org/benman/teaport">Teaport</a>
add this to your dependencies:
Todo add to cocoapods and perhaps others.
Examples
#include <thread>
#include <cstring>
void simple() {
RunBuilder().cout(PipeOption::pipe));
RunBuilder().cin("hello world\n"));
RunBuilder().cin("hello world").cout(PipeOption::pipe));
std::cout <<
"captured: " << process.
cout <<
'\n';
RunBuilder().cerr(PipeOption::pipe)
.cout(PipeOption::pipe)
.check(true)
);
std::cout <<
"cerr was: " << process.
cerr <<
"\n";
#if __cplusplus >= 202002L
.cout = PipeOption::pipe,
.check = false
});
std::cout <<
"captured: " << process.
cout <<
'\n';
#endif
}
void popen_examples() {
.
cout(PipeOption::pipe).popen();
char buf[1024] = {0};
std::cout << buf;
popen.close();
std::thread write_thread([&]() {
popen.close_cin();
});
for (auto& c : buf)
c = 0;
std::cout << buf;
popen.close();
if (write_thread.joinable())
write_thread.join();
}
int main(int argc, char** argv) {
std::cout << "running basic examples\n";
simple();
std::cout << "running popen_examples\n";
popen_examples();
return 0;
}
Design
stdin, stdout, stderr are macros, so it's not possible to use those variable names. Instead c++ variable names is used cin, cout, cerr where the std* would have been respectively.
PopenBuilder was a bad idea. Removed, now only RunBuilder remains which is enough. Have both is too confusing.
current progress
All tests are passing on macos, linux. Most tests pass on cross compiling on linux for windows using mingw. The library is almost feature complete.
must to be implemented
- documentation
- bugs, there is lots of them to be discovered.
- main structure is set in place and help is welcome.
not good
- due to types c++ is more wordy
Changelog
0.2.0
- omg setting check=true is fixed. What a typo