arun11299 / cpp-subprocess

Subprocessing with modern C++
Other
456 stars 90 forks source link

Cannot access process retcode after `communicate()` #13

Closed matthijskooijman closed 6 years ago

matthijskooijman commented 6 years ago

It seems that only Popen::poll() sets Popen::retcode_ (which can be retrieved using Popen::retcode()), but Popen::communicate() instead calls Popen::wait() and throws away the result. I tried calling Popen::poll() myself, but it seems that just returns 0 (IIRC waitpid will only work once).

A simple fix seems to be to let communicate() do retcode_ = wait();, which works, but I'm not sure if that's the best approach here (perhaps wait() should just set it?).

arun11299 commented 6 years ago

Hello @matthijskooijman Thanks for reporting the issue. I think its best that wait returns the retcode instead of setting itself. Thats what I have done in the commit as well.

matthijskooijman commented 6 years ago

Thanks. It seems that setting the return code in wait() would be more like the python version, though: https://stackoverflow.com/a/5631819/740048 (but if you manually call wait, you can of course just save the retcode yourself, so it's not a very big deal).