【发布时间】:2015-06-08 14:33:03
【问题描述】:
我正在尝试从 Python 调用命令行实用程序。代码如下
import subprocess
import sys
class Executor :
def executeEXE(self,executable ) :
CREATE_NO_WINDOW = 0x08000000
process = subprocess.Popen(executable, stdout=subprocess.PIPE,
creationflags=CREATE_NO_WINDOW )
while True:
line = process.stdout.readline()
if line == '' and process.poll() != None:
break
print line
上面代码的问题是我想要上面进程的实时输出,但我没有得到。我在这里做错了什么。
【问题讨论】:
-
subprocess.popen()输出在this answer 中回显的方式可能会有所帮助。 -
这里是another couple of articles that won't help you(看来您使用的是 Windows)。至少使用基于
iter()的循环而不是while-循环。 -
@Sebastian 我认为
readline()语句在某种程度上没有返回输出。我不确定iter()会有什么帮助。是的,我在 Windows 上。
标签: python command-line subprocess