473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Getting stdout from other processes

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?
Feb 22 '08 #1
3 1251
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
Feb 22 '08 #2
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 <mi*********@gmail.com>
http://pythonwise.blogspot.com
Feb 22 '08 #3
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
Feb 23 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andrei D. | last post by:
Hello Python newsgroup, In the process of developing a big ssh wrapper for sending commands to multiple hosts over the last few months, I (almost accidentally, considering I'm really just an...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
8
by: Hugh Macdonald | last post by:
I'm calling a command from within a python script and I need to be able to both catch the output (stdout and stderr) from it and also have the PID (so that I can kill it) I can do one or other...
1
by: Melissa Wallis | last post by:
In a Python script I start a number of C++ processes using os.execlp. Most of these processes output messages for debugging purposes at this time. The problem I am having is that by starting 4 or...
3
by: Harayasu | last post by:
Hi, Using fgets() I can read from stdin and with fputs() I can write to stdout. Now I have two programs, one writing to stdin and the other one reading from stdin. And I would like the second...
7
by: Mathias Herrmann | last post by:
Hi. I have the following problem: Using popen() to execute a program and read its stdout works usually fine. Now I try to do this with a program called xsupplicant (maybe one knows), but I dont...
1
by: notanotheridiot | last post by:
Hi- I'm trying to exec some arbitrary code in one thread of an application and read anything it prints to stdout or stderr in another thread. My question is how? I've tried changing...
8
by: cypher543 | last post by:
This has been driving me insane for the last hour or so. I have search everywhere, and nothing works. I am trying to use the subprocess module to run a program and get its output line by line. But,...
6
by: gregpinero | last post by:
Let's say I have this Python file called loop.py: import sys print 'hi' sys.stdout.flush() while 1: pass And I want to call it from another Python process and read the value 'hi'. How...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.