title: os command is not writing into file
body: <p>I have below code :</p>
  
  <pre><code> import os, subprocess
   def cfile():
          p = r'/mypath/abc'
          cmd = ["who am i | awk '{print $1}'"]
          if not os.path.exists(p):
                  fh = open(p, 'a')
                  try:
                       subprocess.Popen(cmd, stdout=fh)
                  finally:
                       fh.close()
   cfile()
  </code></pre>
  
  <p>above code is creating the file called 'folder' but not writing anything. Can you please help me to get to know what is wrong here. I am using python 2.7</p>