When I'm running python3 interpreter on Linux machine and trying to redirect it's stdout to file like this, nothing happens:
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. 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 ).
What's the difference? Are python writes all it's output to another stream than stdout, or what?
-
Possible duplicate of Redirect stdout to a file in Python?, Redirect stderr and stdout in Bash, etc.jww– jww2018年09月10日 13:11:33 +00:00Commented Sep 10, 2018 at 13:11
-
@jww, the question you mention is about noninteractive mode. Please read the comment of my answerRomeo Ninov– Romeo Ninov2018年09月10日 13:15:37 +00:00Commented Sep 10, 2018 at 13:15
1 Answer 1
For your case seems python send information to STDERR and not to STDOUT. So you should use redirect like:
user@workmachine:~$ python3 2> python.txt
1 Comment
read -p "Type something: " will display its prompt on stderr.