How to append output of “python --version” to a file in bash shell?

前端 未结 2 767
后悔当初
后悔当初 2021-01-07 13:37

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 ignor

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-07 14:14

    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.

提交回复
热议问题