Python-捕获Popen stdout并在控制台上显示? [英] Python - capture Popen stdout AND display on console?

查看:135
本文介绍了Python-捕获Popen stdout并在控制台上显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从通过subprocess.Popen(...)开始的长时间运行的进程中捕获标准输出,因此我将stdout=PIPE用作arg.

I want to capture stdout from a long-ish running process started via subprocess.Popen(...) so I'm using stdout=PIPE as an arg.

但是,由于这是一个长期运行的过程,因此我也想将输出发送到控制台(好像我没有通过管道将其发送给控制台),以使脚本用户知道它仍在工作.

However, because it's a long running process I also want to send the output to the console (as if I hadn't piped it) to give the user of the script an idea that it's still working.

这有可能吗?

干杯.

推荐答案

在从管道中读取它时,您能否简单地print它?

Can you simply print it as you read it from the pipe?

这篇关于Python-捕获Popen stdout并在控制台上显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆