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

前端 未结 2 766
后悔当初
后悔当初 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:10

    a simpler solution is:

    python --version 2>> path.log
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题