def run(cmd, logfile):
    p = subprocess.Popen(cmd, shell=True, universal_newlines=True, stdout=
        logfile)
p.wait()
Saving stdout from subprocess.Popen to file, plus writing more stuff to the file