473,387 Members | 1,529 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.

Simultaneous output parsing of child process?

Hello,

Hopefully someone can help me out with this issue...

I have a python script that needs to run a shell command and be able
to react to output from that command as it occurs (as opposed to
waiting for the whole command to complete and then parsing the
output). Is this possible with Python?

I created a test script that prints a line of output to stdout every 4
seconds or so. I want to create a "parent" script that kicks off the
test script, and prints data as soon as the test script sends anything
to the standard output (ie. every 4 seconds).

Furthermore, the solution needs to support Windows, several flavors of
UNIX and potentially LINUX.

I would ideally like to have the following type of behaviour:

childPipe = kickOffChild('test.py')
while <child process still active>:
line = childPipe.checkForStdOutput()
if line: # This should trigger once every 4 seconds in the
example above
print "OUTPUT:", line
print "Process completed."
Any help would be greatly appreciated.

Fraser
Jul 18 '05 #1
2 2149

"Fraser Gordon" <fr***********@cognos.com> wrote in message
news:de**************************@posting.google.c om...
Hello,

Hopefully someone can help me out with this issue...

I have a python script that needs to run a shell command and be able
to react to output from that command as it occurs (as opposed to
waiting for the whole command to complete and then parsing the
output). Is this possible with Python?

I created a test script that prints a line of output to stdout every 4
seconds or so. I want to create a "parent" script that kicks off the
test script, and prints data as soon as the test script sends anything
to the standard output (ie. every 4 seconds).

Furthermore, the solution needs to support Windows, several flavors of
UNIX and potentially LINUX.

Perhaps something that Donn Cave posted a few years ago helps, particularly
the bonus version ;-):

http://groups.google.com/groups?selm...washington.edu

It doesn't work as is on windows, but I've used it as a base on linux
several times.

HTH,

--
Emile van Sebille
em***@fenx.com

Jul 18 '05 #2

"Fraser Gordon" <fr***********@cognos.com> wrote in message
news:de**************************@posting.google.c om...
Hello,

Hopefully someone can help me out with this issue...

I have a python script that needs to run a shell command and be able
to react to output from that command as it occurs (as opposed to
waiting for the whole command to complete and then parsing the
output). Is this possible with Python?

I created a test script that prints a line of output to stdout every 4
seconds or so. I want to create a "parent" script that kicks off the
test script, and prints data as soon as the test script sends anything
to the standard output (ie. every 4 seconds).

Furthermore, the solution needs to support Windows, several flavors of
UNIX and potentially LINUX.

I would ideally like to have the following type of behaviour:

childPipe = kickOffChild('test.py')
while <child process still active>:
line = childPipe.checkForStdOutput()
if line: # This should trigger once every 4 seconds in the
example above
print "OUTPUT:", line
print "Process completed."
Any help would be greatly appreciated.
You need to use separate threads to process stdin, stdout and
stderr. Otherwise, you'll run the risk of a deadlock.

Unfortunately, the select service does not work on Windows
in all circumstances, so you can't simply switch between the
different files as needed.

John Roth

Fraser

Jul 18 '05 #3

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

Similar topics

3
by: Yuan HOng | last post by:
In my program I have to call an external program and parse its output. For that I use the os.popen2 function, and then read the output stream. But the complexity is that the external program...
2
by: Hoegje | last post by:
I am writing a C++ program, which should create a sub- process to start a telnet session to another server. Then it should login to that server (on the telnet login) and execute one or more...
3
by: Bo | last post by:
In my asp.net webservice application, I need to launch a DOS process as authorized users. To impersonate users, I use <impersonation = true> in my webconfig. I can't use Diagnostics.Process.Start,...
8
by: dmoore | last post by:
Hi folks, I've seen the following issue come up in multiple posts to this mailing list: I have a python program that spawns a child process with popen or popen2 or popen3 or popen2.popen2...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.