0

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?

jww
  • 97,681
  • 90
  • 411
  • 885
Uroboros
  • 189
  • 2
  • 12
  • Possible duplicate of [Redirect stdout to a file in Python?](https://stackoverflow.com/q/4675728/608639), [Redirect stderr and stdout in Bash](https://stackoverflow.com/q/637827/608639), etc. – jww Sep 10 '18 at 13:11
  • @jww, the question you mention is about noninteractive mode. Please read the comment of my answer – Romeo Ninov Sep 10 '18 at 13:15

1 Answers1

2

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
Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31
  • 1
    It's common for interactive programs to write to stderr instead of stdout. For example, `read -p "Type something: "` will display its prompt on stderr. – John Kugelman Sep 10 '18 at 13:11