Ad

How To Make `python2 -V >> Myfile` "work"?

- 1 answer

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.

Ad

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
Ad
source: stackoverflow.com
Ad