title: python stdout redirection and returncode
body: <p>Can't get return code of subprocess with "global" redirection of stdout to log file:
  F.e.:</p>
  
  <pre><code>    &gt;&gt;&gt; rc = subprocess.call(['ping', '-c1', 'google.com'])
      PING google.com (173.194.69.102) 56(84) bytes of data.
      64 bytes from bk-in-f102.1e100.net (173.194.69.102): icmp_seq=1 ttl=46 time=86.1 ms
      --- google.com ping statistics ---
      1 packets transmitted, 1 received, 0% packet loss, time 0ms
      rtt min/avg/max/mdev = 86.141/86.141/86.141/0.000 ms
      &gt;&gt;&gt; rc
      0
  </code></pre>
  
  <p><strong>rc</strong> is <strong>0</strong> and i can work with it, BUT if do:</p>
  
  <pre><code>    &gt;&gt;&gt; sys.stdout=open('/var/log/test','a')
      &gt;&gt;&gt; rc = subprocess.call(['ping', '-c1', 'google.com'])
      PING google.com (173.194.69.102) 56(84) bytes of data.
      64 bytes from bk-in-f102.1e100.net (173.194.69.102): icmp_seq=1 ttl=46 time=86.9 ms
      --- google.com ping statistics --- 
      1 packets transmitted, 1 received, 0% packet loss, time 0ms
      rtt min/avg/max/mdev = 86.947/86.947/86.947/0.000 ms
      &gt;&gt;&gt; rc
      &gt;&gt;&gt; sys.stdout.flash()
  </code></pre>
  
  <p>1st - rc goes to file, and not in view of script anymore. So I can't work with it.</p>
  
  <p>2nd - only after sys.stdout.flash()</p>
  
  <p>3rd - ping result goes to file only if i do</p>
  
  <pre><code> rc = subprocess.call(['ping', '-c1', 'google.com'],stdout=sys.stdout)
  </code></pre>
  
  <p>The main question is how to prevent redirection of return code to stdout file?</p>