[英]Python output redirecting
When I'm running python3
interpreter on Linux machine and trying to redirect it's stdout
to file like this, nothing happens: 当我在Linux机器上运行
python3
解释器并尝试将其stdout
重定向到这样的文件时,没有任何反应:
user@workmachine:~$ python3 > python.txt
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
\>>>
File python.txt
remains empty while interpreter is running as well as after it was closed. 在解释器运行时以及关闭后,文件
python.txt
保持为空。 All it's output is still in terminal. 它的所有输出仍在终端中。
On the other hand, if I'm redirecting R
interpreter the same way ( R > R.txt
) the result is as expected ( all output redirected to file, see nothing in terminal ). 另一方面,如果我以相同的方式重定向
R
解释器( R > R.txt
),则结果与预期的一样(所有输出都重定向到file,在terminal中看不到任何内容)。
What's the difference? 有什么不同? Are python writes all it's output to another stream than
stdout
, or what? 是python将所有输出写入
stdout
以外的其他流,还是什么?
For your case seems python send information to STDERR and not to STDOUT. 对于您的情况,似乎python将信息发送到STDERR而不是STDOUT。 So you should use redirect like:
因此,您应该使用重定向,例如:
user@workmachine:~$ python3 2> python.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.