title: How to execute a python script and write output to a file?
body: <p>i have the following script in python with a while loop</p>
  
  <pre><code>from time import sleep
      while True:
          print "hola"
          print "mundo"
          sleep(2)
  </code></pre>
  
  <p>and i want to write the output to a file with the following code:</p>
  
  <pre><code>import subprocess
      with open("output.log", "w") as output:
      subprocess.call(["python", "./main.py"], stdout=output);
  </code></pre>
  
  <p>the thing is that the while never ends, the file output.log never gets the output from the script, i wonder if there is a way to do it.</p>