Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > read pipe information on a running (popen) process

Reply
Thread Tools

read pipe information on a running (popen) process

 
 
Jules Stevenson
Guest
Posts: n/a
 
      01-06-2009
Hi,

I'm really struggling with how to read the stdout on a running process. All
the examples I've seen tend to rely on waiting for the process to finish.
The process I'm running takes a while and I need to get stdout [and stderr]
and be able to pipe them into a string for displaying in a web app.

My shoddy code is currently this:

p = subprocess.Popen('xsibatch.exe -s', bufsize=200, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)

while p.returncode==None:
p.poll()
print p.stdout.readline(), p.stderr.readline(),
time.sleep(1)

print 'finished'

Which results in it printing (i think) the last line written to the pipe
file. I'm thinking there must be a simpler way to access this information.
Ideally I'd like to dump the whole lot to a string at periodic intervals but
am completely stumped as to how to do this as readlines() and many other
methods require an EOF.

On a side note [and much lesser problem currently], I was under the
impression that p.poll() writes the returncode attribute, but from what I
can see when the process terminates p.poll() still returns none?

Many thanks,

Jules

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Asynchronous process to process pipe IO Pito Salas Ruby 11 08-26-2009 09:13 AM
pipe possible to an already running process? .rhavin grobert Perl Misc 2 01-09-2006 03:43 PM
pipe to an already running process? .rhavin grobert Perl Misc 0 01-08-2006 11:47 PM
finding the PID of a process running as an anonymous pipe Richard Perl Misc 2 05-27-2005 06:22 PM
[named pipe] i wanna know about validate of pipe handle of client lee, wonsun C++ 1 11-02-2004 04:29 AM



Advertisments