开发者

Directing script output to a file using subprocess?

From within a python script ("main.py"), I am using the subprocess module to run another script ("sub_script.py").

Here's the code in the "main.py" script that 'runs' "sub_scrip开发者_StackOverflow社区t.py":

subprocess.Popen([sys.executable, "sub_script.py"])

this works fine as long as "sub_script.py" does not have any "print" statements in it.

I now want to channel all the output of "sub_script.py" to an external file ("log.txt").

How do I do it?


subprocess.Popen([sys.executable, "sub_script.py"], stdout=open("log.txt", "a"))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜