[Python-ideas] Adding a subprocess.CompletedProcess class
Paul Moore
p.f.moore at gmail.com
Sun Feb 1 23:06:53 CET 2015
On 1 February 2015 at 16:29, Wes Turner <wes.turner at gmail.com> wrote:
>> The thing I've ended up needing to do once or twice, which is
>> unreasonably hard with subprocess, is to run the command and capture
>> the output, but *still* write it to stdout/stderr. So the user gets to
>> see the command's progress, but you can introspect the results
>> afterwards.
>>
>>
>> The hard bit is to do this while still displaying the output as it
>> arrives. You basically need to manage the stdout and stderr pipes
>> yourself, do nasty multi-stream interleaving, and deal with the
>> encoding/universal_newlines stuff on the captured data. In a
>> cross-platform way :-(
>
> http://sarge.readthedocs.org/en/latest/tutorial.html#buffering-issues
I'm not sure how that's relevant. Sure, if the child buffers output
there's a delay in seeing it, but that's no more an issue than it
would be for display on the console.
> '| tee filename.log'
There's a number of problems with this:
1. Doesn't handle stderr
2. Uses a temporary file, which I'd then need to read in the parent
process, and delete afterwards (and tidy up if there's an exception)
3. tee may not be available (specifically on Windows)
4. Uses an extra process, which is a non-trivial overhead
Paul
More information about the Python-ideas
mailing list