Getting stdout from other processes

  • Thread starter Matthias Vogelgesang
  • Start date
M

Matthias Vogelgesang

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?
 
D

Diez B. Roggisch

Matthias said:
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
 
M

Miki

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,
 
M

Matthias Vogelgesang

Hi,
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top