polling for output from a subprocess module
- From: jakub.hrozek@xxxxxxxxx
- Date: Mon, 4 Feb 2008 04:29:40 -0800 (PST)
Hello,
My program uses the subprocess module to spawn a child and capture its
output. What I'd like to achieve is that stdout is parsed after the
subprocess finishes, but anything that goes to stderr is printed
immediately. The code currently looks like:
try:
test = Popen(test_path,
stdout=PIPE,
stderr=PIPE,
close_fds=True,
env=test_environ)
while test.poll() == None:
ready = select.select([test.stderr], [], [])
if test.stderr in ready[0]:
t_stderr_new = test.stderr.readlines()
if t_stderr_new != []:
print "STDERR:", "\n".join(t_stderr_new)
t_stderr.extend(t_stderr_new)
except OSError, e:
print >>sys.stderr, _("Test execution failed"), e
else:
self.result.return_code = test.returncode
self.result.process(test.stdout.readlines(), t_stderr)
The problem is, that it seems that all the output from the subprocess
seems to be coming at once. Do I need to take a different approach?
.
- Follow-Ups:
- Re: polling for output from a subprocess module
- From: Thomas Bellman
- Re: polling for output from a subprocess module
- Prev by Date: Re: Elementary string-parsing
- Next by Date: Too many open files
- Previous by thread: Problem with Image: Opening a file
- Next by thread: Re: polling for output from a subprocess module
- Index(es):
Relevant Pages
|