Python子进程输出到stdout

时间:2011-05-19 17:15:18

标签: python subprocess stdout

我正在使用子进程模块从python运行二进制文件。

要捕获二进制文件产生的输出,我正在使用:

proc = subprocess.Popen (command_args, shell=False, stdout=subprocess.PIPE)
out = proc.communicate()[0]
#print the output of the child process to stdout
print (out)

这样做是在完成执行后打印进程的输出。无论如何我可以在程序执行时将此输出打印到stdout吗?我真的需要看看输出是什么,因为这些程序可以运行很长时间。

感谢您的帮助。

1 个答案:

答案 0 :(得分:12)

只是不要将输出发送到管道:

proc = subprocess.Popen (command_args, shell=False)
proc.communicate()
相关问题