subprocess pipe question
Rita
rmorgan466 at gmail.com
Tue Feb 22 18:44:20 EST 2011
I have a process like this,
def run(cmd):
#cmd=a process which writes a lot of data. Binary/ASCII data
p=subprocess.Popen(cmd,stdout=subprocess.PIPE)
I would like to get cmd's return code so I am doing this,
def run(cmd):
p=subprocess.Popen(cmd,stdout=subprocess.PIPE)
rc=p.poll()
print rc # and I get 'None' regardless of what cmd gives me (0 thru 255
are valid return codes)
return p.stdout
When using wait() it works a bit better but not consistent
def run(cmd):
p=subprocess.Popen(cmd,stdout=subprocess.PIPE)
rc=p.wait()
print rc
return p.stdout
When the output of cmd is a small ascii file it works perfectly fine, but
when the file is large (more than 2MB) the process just waits for ever (I am
guessing its blocking?). When I use the communicate call it works perfectly
but my process is consuming way too much memory.
Is there a better way to get my return code consistently efficiently and not
take up so much memory?
--
--- Get your facts first, then you can distort them as you please.--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110222/ca556dc0/attachment.html>
More information about the Python-list
mailing list