473,659 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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('t est.py')
while <child process still active>:
line = childPipe.check ForStdOutput()
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 2167

"Fraser Gordon" <fr***********@ cognos.com> wrote in message
news:de******** *************** ***@posting.goo gle.com...
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.goo gle.com...
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('t est.py')
while <child process still active>:
line = childPipe.check ForStdOutput()
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
1829
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 gives back its output in a piecemeal manner, with long delays between the outputs. In the main program I want to therefore read the output in a non-blocking manner, to read as many bytes as the child process is spitting out. The question is, how...
2
4353
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 command(s) on the remote server. The C++ program provides all the input for this process (username, password, servername, commands, ...) and should capture all the output returned by the telnet session process inside some variable. How can this be...
3
7952
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, because it creates a child process using parent process token "System", not the impersonated thread token. I don't want to use CreateProcessWithLogonW, because my application impersonates different users and it is not a good idea to handle...
8
2885
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 etc. the child process is interactive: it asks for input then spits out some output, asks for more input then spits out some output. for example, consider the trivial child program:
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8339
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.