On Sun, Feb 1, 2015 at 7:48 AM, Paul Moore <p.f.moore@gmail.com> wrote:
 29 January 2015 at 21:09, Thomas Kluyver <thomas@kluyver.me.uk> wrote:
> On 29 January 2015 at 03:47, Nick Coghlan <ncoghlan@gmail.com> wrote:
>> I still suspect we should be offering a simpler way to decouple the
>> creation of the pipes from the subprocess call, but I have no idea
>> what that API should look like,
> Presumably that would need some kind of object representing a
> not-yet-started process.


p = sarge.run('sleep 60', async=True)
assert type(p) == sarge.Pipeline
Technically, that could be Popen, but for backwards
> compatibility the Popen constructor needs to start the process, and p =
> Popen(..., start=False) seems inelegant.

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

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 :-(


 '| tee filename.log'