Print the subprocess output directly to stdout and stderr.

This commit is contained in:
Alexis Lopez Zubieta
2018-08-04 12:33:41 -05:00
parent 9743988c80
commit 18f2d94241
+2 -48
View File
@@ -134,54 +134,8 @@ namespace linuxdeploy {
}
log << std::endl;
auto process = subprocess::Popen(args, subprocess::output{subprocess::PIPE}, subprocess::error{subprocess::PIPE});
std::vector<pollfd> pfds(2);
auto* opfd = &pfds[0];
auto* epfd = &pfds[1];
opfd->fd = fileno(process.output());
opfd->events = POLLIN;
epfd->fd = fileno(process.error());
epfd->events = POLLIN;
auto printOutput = [&pfds, opfd, epfd, this, &process]() {
poll(pfds.data(), pfds.size(), -1);
if (opfd->revents & POLLIN) {
std::ostringstream oss;
std::vector<char> buf(4096);
auto* lineptr = buf.data();
auto n = buf.size();
while (getline(&lineptr, &n, process.output()) != -1) {
oss << "[" << d->name << "/stdout] " << buf.data();
}
linuxdeploy::core::log::ldLog() << oss.str();
}
if (epfd->revents & POLLIN) {
std::ostringstream oss;
std::vector<char> buf(4096);
auto* lineptr = buf.data();
auto n = buf.size();
while (getline(&lineptr, &n, process.error()) != -1) {
oss << "[" << d->name << "/stderr] " << buf.data();
}
linuxdeploy::core::log::ldLog() << oss.str();
}
};
do {
printOutput();
} while (process.poll() < 0);
printOutput();
auto process = subprocess::Popen(args, subprocess::output{stdout}, subprocess::error{stderr});
process.wait();
return process.retcode();
}