title: python Save the output of a shell command into a text file
body: <p>I want to save the output of a shell command into a textfile via python. This is my actual, pretty basic python code:</p>
  
  <p><strong>Edit</strong> <em>here is the final script, thank you for your help :)</em></p>
  
  <pre><code>import subprocess
  
  ip_adress_4 = 0    
  pr = open("pointer_record.txt", "w")
  
  while (ip_adress_4 &lt; 255):
      ip_adress_4 = ip_adress_4 + 1
      ip_adress = '82.198.205.%d' % (ip_adress_4,)
      subprocess.Popen("host %s" % ip_adress, stdout=pr, shell=True)
  </code></pre>