reading shell output in parallel
P at draigBrady.com
P at draigBrady.com
Mon Aug 16 06:48:45 EDT 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:
http://www.pixelbeat.org/libs/subProcess.py
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")
while process.read(1):
handle(process.outdata, process.errdata)
del(process)
Pádraig.
More information about the Python-list
mailing list