I\'m calling a python script (B) from another python script (A).
Using subprocess.call, how do I redirect the stdout of B to a file that specify?
I\'m using
Pass a file as the stdout
parameter to subprocess.call
:
with open('out-file.txt', 'w') as f:
subprocess.call(['program'], stdout=f)
Alternate approach
import subprocess
p=subprocess.Popen('lsblk -l|tee a.txt',stdout=subprocess.PIPE,shell=True)
(output,err)=p.communicate()
p_status=p.wait()
print output
Above code will write output of command to file a.txt