1

How do I redirect the output of python version into a text file in linux?

I tried the following:

python --version > old.txt

The text file is getting created but it is empty. Simple question, but beginner here.

1

1 Answer 1

4

The Python version is output to stderr rather than stdout which is what your command is writing to the file. In order to write the contents of stderr you will want to write:
python --version 2> old.txt

Sign up to request clarification or add additional context in comments.

2 Comments

Any reason why it gets output to the STDERR stream?
Not particularly, some programs just prefer to use stderr to print meta-information (as well as the usual warnings and error messages).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.