首页 > 解决方案 > 使用输入从python运行exe文件并保存输出

问题描述

我想从python运行一个带有输入的exe文件并保存输出而不打印它,有人知道我该怎么做吗?

标签: python-3.xexeuser-inputpython-3.3

解决方案


是的你可以。https://docs.python.org/2/library/subprocess.html#module-subprocess

import subprocess

with open('mylog.txt', 'a') as log, open('myerror.txt', 'a') as error_log:
    process = subprocess.call(['ls', '-l'], stderr=error_log, stdout=log)

推荐阅读