<html><body bgcolor="#FFFFFF"><div><br></div><div>On 22/02/2011, at 20:44, Rita <<a href="mailto:rmorgan466@gmail.com">rmorgan466@gmail.com</a>> wrote:<br><br></div><div></div><blockquote type="cite"><div>I have a process like this,<br><br>def run(cmd):<br>  #cmd=a process which writes a lot of data. Binary/ASCII data<br>  p=subprocess.Popen(cmd,stdout=subprocess.PIPE)<br><br>I would like to get cmd's return code so I am doing this,<br>
<br>def run(cmd):<br>  p=subprocess.Popen(cmd,stdout=subprocess.PIPE)<br>  rc=p.poll()<br>  print rc # and I get 'None' regardless of what cmd gives me (0 thru 255 are valid return codes)<br>  return p.stdout<br><br>
<br>When using wait() it works a bit better but not consistent<br>def run(cmd):<br>  p=subprocess.Popen(cmd,stdout=subprocess.PIPE)<br>  rc=p.wait()<br>  print rc<br>  return p.stdout<br><br>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. <br>
<br>Is there a better way to get my return code consistently efficiently and not take up so much memory? <font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#0023A3"><br></font></font></div></blockquote><br><div>Have you tried: p.return_code (or something like this? I don't remember now)</div></body></html>