1: 2: 3: 4: 5: 6: 7: 8:
from subprocess import Popen name = 'test.txt' outfile = open(name,'w') command = [ 'ls','-l' ] sub_proc = Popen(command,stdout=outfile) sub_proc.wait() # wait till subprocess is finished outfile.close()