简体   繁体   English

如何捕获用pythonw执行的Python脚本的标准输出?

[英]How to capture stdout of a Python script executed with pythonw?

When a script is executed with pythonw it will not open a console. 使用pythonw执行脚本时,它将不会打开控制台。

Is there a way to capture the stdout of such a script by keeping the usage of pythonw ? 有没有办法通过保持pythonw的使用来捕获此类脚本的stdout

Note, I am looking for a solution that does not require the modification of the script (I know that I can use logging) 注意,我正在寻找不需要修改脚本的解决方案(我知道我可以使用日志记录)

Update: pythonw script.py >somefile seems to work. 更新: pythonw script.py >somefile似乎正常工作。 How can I redirect it to console? 如何将其重定向到控制台?

很明显: pythonw script.py|more

如果可以更改调用方式(如在更新中所做的那样),为什么不仅使用python而不是pythonw运行它?

python script.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM