subprocess pipe question
GMail Felipe
felipe.vinturini at gmail.com
Tue Feb 22 19:29:26 EST 2011
On 22/02/2011, at 20:44, Rita <rmorgan466 at gmail.com> wrote:
> 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?
Have you tried: p.return_code (or something like this? I don't remember now)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110222/4820b990/attachment-0001.html>
More information about the Python-list
mailing list