如何将.exe的输出重定向到python中的文件? [英] How to redirect the output of .exe to a file in python?
本文介绍了如何将.exe的输出重定向到python中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在脚本中,我想运行.exe,其命令行参数为-a,然后
In a script , I want to run a .exe with some command line parameters as "-a",and then
将程序的标准输出重定向到一个文件?
redirect the standard output of the program to a file?
我该如何实现?
推荐答案
你可以使用子进程直接重定向到文件。
You can redirect directly to a file using subprocess.
import subprocess
with open('output.txt', 'w') as output_f:
p = subprocess.Popen('Text/to/execute with-arg',
stdout=output_f,
stderr=output_f)
这篇关于如何将.exe的输出重定向到python中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文