Jan Jan - 3 months ago 10
Python Question

How to make `python2 -V >> myfile` "work"?

I want to automatically record my python version in a computerinfo file. However

python2 -V >> myfile


prints only to the console but not to
myfile
. How can I get the output into a file?

Curiously, for python3 --
python3 -V >> myfile
-- this works as I expected.

I am on Ubuntu 16.04 and I use the bash shell.

Answer

There is a bug in python2 -V, that prints the version as stderr instead of stdout. Try to redirect the stderr like:

python2 -V 2>> myfile