我正在使用subprocess模块从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)
这段代码的作用是在进程执行完成后将输出打印出来。有没有办法在程序执行的同时将输出打印到标准输出?我真的需要查看输出结果,因为这些程序可能运行很长时间。
感谢帮助。