Reputation: 1886
I'm trying to write a short script to log certain environment variables of my current shell session to file. Unfortunately the output of "python --version" seems to ignore (?) the >> operator and prints to the shell instead to the file.
My minimal (not) working example:
rm path.log
echo "python --version" >> path.log
python --version >> path.log
I would expect that the file path.log would then have the following content:
python --version
Python 2.6.6
But the line "Python 2.6.6" is printed to the shell and not to the file. How can I fix this?
Thank you!
PS: This works completely fine for
gcc --version
Upvotes: 1
Views: 895
Reputation: 123448
python --version
outputs to STDERR
.
You need to merge STDERR
into STDOUT
:
python --version >> path.log 2>&1
For reference, you can verify such behavior by saying:
$ python --version 1>/dev/null
Python 2.7.4
The STDOUT
in the above example was redirected to /dev/null
. This would imply that the output is being sent to STDERR
.
Upvotes: 7