【发布时间】:2014-09-10 03:18:18
【问题描述】:
我有一个朋友给我的可执行文件 (hello.exe)。该可执行文件创建另一个 exe 文件 (test.exe) 并通过另一个命令行窗口运行该可执行文件。我想尝试编写一个运行 hello.exe 的脚本,并获取 test.exe 的输出。我对 python 很陌生,熟悉系统调用和重定向输出,但这是一种特殊情况,因为我没有直接访问 test.exe。我面临的另一个问题是 hello.exe 在执行任何其他操作之前等待来自 test.exe 的键盘响应。我是否可以运行我的 hello.exe 脚本并在同一脚本中获取 test.exe 的输出?
import sys, string, os
os.system(hello.exe) > "test.txt" //Something like this?? Grab output from test.exe and put in test.txt
print "test" //this doesn't print until keystroke from terminal running test.exe
【问题讨论】:
-
一般以“是否可能”开头的问题总是以“是的,可能的”来回答,但它可能不可行
-
看看
subprocess.Popen类和communicate方法。 -
@JoranBeasley 有什么更好的表达方式?
标签: python windows redirect io system