title: In Python how the write output of a command into a file
body: <p>I want to write a python script that should execute multiple commands one by one and the output should be saved into a file in append mode. I tried writing a script, it is working for single command but how to write for multiple command.</p>
  
  <pre><code>import subprocess
  with open(filename, "a") as output:
      subprocess.Popen('cmd1''cmd2''cmd3', shell=True, stdout=output)  
  </code></pre>
  
  <p>For eg:</p>
  
  <pre><code>cmd1 = dir
  cmd2 = whoami
  </code></pre>
  
  <p>The file should contain the output of both commands one after the other.</p>