How do I redirect stdout to a file when using subprocess.call in python?

后端 未结 2 1880
醉酒成梦
醉酒成梦 2020-12-01 14:53

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

2条回答
  •  臣服心动
    2020-12-01 15:33

    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

提交回复
热议问题