title: Python problem executing popen in cron
body: <p>I use <code>popen</code> to execute commands in a Python script, and I call it via cron.<br>
  Cron calls out this script but the behavior isn't the same if I call it by hand.</p>
  
  <h3>Source:</h3>
  
  <pre><code>from subprocess import Popen, PIPE
  
  pp = Popen('/usr/bin/which iptables', shell=True, stdout=PIPE)
  
  data = ''
  for ln in pp.stdout:
      data = data+ln
  
  if data == '':
      print 'ko'
  else:
      print 'ok : '+data
  </code></pre>
  
  <h3>By hand:</h3>
  
  <pre><code># python /home/user/test.py
  &gt; : /sbin/iptables
  </code></pre>
  
  <h3>By cron (in /tmp/err_cron):</h3>
  
  <pre><code>* * * * * /usr/bin/python /home/user/test.py &gt;&gt; /tmp/err_cron
  ko
  ko
  ko
  </code></pre>
  
  <p>Why does cron not run this script normally?</p>