[英]print out the on-screen-output from a python program to a file without writing them to a file inside the python program
如何在Linux上将python程序的屏幕输出打印到文件而不将其写入python程序内部的文件?
我用:
my.py> my.log
但运行my.py后不存在my.log,效果很好。
任何帮助将不胜感激 !
假设您的程序将其输出发送到控制台,这应该将标准输入和标准错误流my.log
到bash
shell中的my.log
中:
$ my.py >my.log 2>&1
要使输出可见,可以使用tee
:
$ my.py 2>&1 | tee my.log
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.