reading shell output in parallel

P at P at
Mon Aug 16 12:48:45 CEST 2004

Steve wrote:
> Hi,
> I'm pretty new to python.  I am trying to write a simple application
> that can read the stdout output from a command in linux.  I've tried
> using x = commands.getstatusoutput() but this only gives back the
> output in x after finished executing.  I would like to read the
> contents as it is being shown on the screen and then send parts of
> this info over a simple client/server setup.  I have the client/server
> part set up already.
> Can anyone suggest a simple way to do this?  
> Thanks for your help, I appreciate it.

Better support is being added for this.
In the meantime you could use this:
With this you specify the timeout in seconds
so you would update client every 1 second rather
than every read (around 4K) which may or
may not be what you want.

Usage is like:

import subProcess
process = subProcess.subProcess("your shell command")
     handle(process.outdata, process.errdata)


More information about the Python-list mailing list