On 22/02/2011, at 20:44, Rita <rmorgan...@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)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to