From 18f2d94241ae2e45288aeab6a4dc270dcc71f0e0 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sat, 4 Aug 2018 12:33:41 -0500 Subject: [PATCH] Print the subprocess output directly to stdout and stderr. --- include/linuxdeploy/plugin/base_impl.h | 50 ++------------------------ 1 file changed, 2 insertions(+), 48 deletions(-) diff --git a/include/linuxdeploy/plugin/base_impl.h b/include/linuxdeploy/plugin/base_impl.h index 2dce3de..0eb7d62 100644 --- a/include/linuxdeploy/plugin/base_impl.h +++ b/include/linuxdeploy/plugin/base_impl.h @@ -134,54 +134,8 @@ namespace linuxdeploy { } log << std::endl; - auto process = subprocess::Popen(args, subprocess::output{subprocess::PIPE}, subprocess::error{subprocess::PIPE}); - - - std::vector 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 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 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(); }