1

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

2 Answers 2

7

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.

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

Comments

2

a simpler solution is:

python --version 2>> path.log

1 Comment

Yup, no need to involve standard output at all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.