chigraph  master
Systems programming language written for beginners in LLVM
SubprocessExample.cpp
#include <chi/Subprocess.hpp>
#include <chi/Result.hpp>
#include <iostream>
int main() {
#ifdef WIN32
"C:\\Windows\\System32\\cmd.exe"
#else
"/bin/sh"
#endif
};
std::string stdOut;
child.attachStringToStdOut(stdOut);
res += child.start();
if (!res) {
std::cerr << res << std::endl;
return 1;
}
std::string dataToSend = "echo hello";
res += child.pushToStdIn(dataToSend.data(), dataToSend.size());
if (!res) {
std::cerr << res << std::endl;
return 1;
}
res += child.closeStdIn();
if (!res) {
std::cerr << res << std::endl;
return 1;
}
int exitCode = child.exitCode();
if (exitCode != 0) {
std::cerr << "Failed run /bin/sh < 'echo hi' with exit code: " << exitCode << std::endl;
return 1;
}
std::cout << stdOut << std::endl;
}