[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Getting stdout from other processes

Matthias Vogelgesang

2/22/2008 2:21:00 PM

Hello,
as I found out, it is possible to get the output of other programs
using os.popen() and read from it. However this method is blocking for
server processes and programs that don't stop immediately. Has anyone
an idea how to get the output of such programs?
3 Answers

Diez B. Roggisch

2/22/2008 3:46:00 PM

0

Matthias Vogelgesang schrieb:
> Hello,
> as I found out, it is possible to get the output of other programs
> using os.popen() and read from it. However this method is blocking for
> server processes and programs that don't stop immediately. Has anyone
> an idea how to get the output of such programs?

Use either the module select to dispatch in case of arriving input on
one of several filedescriptors, or a thread to poll the data

Diez

Miki

2/22/2008 5:56:00 PM

0

Hello Matthias,

> as I found out, it is possible to get the output of other programs
> using os.popen() and read from it. However this method is blocking for
> server processes and programs that don't stop immediately. Has anyone
> an idea how to get the output of such programs?
The current "official" module to use is subprocess (pipe =
Popen([client], stdout=PIPE))
However if the client is sending data, reading from the pipe.stdout
will block the server.
If you *need* to wait, then you can use pipe.wait(), otherwise do as
Diez suggested and have a thread
read the client output and propagate it to the main loop (maybe using
Queue.Queue)

HTH,
--
Miki <miki.tebeka@gmail.com>
http://pythonwise.bl...

Matthias Vogelgesang

2/23/2008 2:44:00 PM

0

Hi,

Miki wrote:
> The current "official" module to use is subprocess (pipe =
> Popen([client], stdout=PIPE))
> However if the client is sending data, reading from the pipe.stdout
> will block the server.
> If you *need* to wait, then you can use pipe.wait(), otherwise do as
> Diez suggested and have a thread
> read the client output and propagate it to the main loop (maybe using
> Queue.Queue)

Thanks both of you for your explanations. In fact, it did the trick.

--
Matthias