Depending on the version of python, the output by executing the "python -V" command is divided into the case of outputting with stdout and the case of outputting with stderr ....
When checking the Python version, you will type a command like the one below.
python -V
python2 -V
python3 -V
Everyone reads the version displayed on the command line. However, when I tried to get this output with Shell game, I was addicted to a petite trap .... Python has a different version output method depending on the version. There are two ways to output with STDOUT and output with STDERR.
* Confirmation of python2
python2 -V 2>stderr
* Confirmation of python3
python3 -V 2>stderr
If the version information is output on the command line when the command is executed above, the python version that outputs the version information on the standard output stdout.
cat stderr
If you can see the version information on, use stderr to get the version information. Python version
If you straddle multiple environments, you'll get frustrated with Shell games!
Well, it's a hassle, so maybe the following is fine ...?
python2 -V 1 > std 2>&1 & cat std
python2 -V 1 > std 2>&1 & cat std
Reference: https://bugs.python.org/issue18338#msg192122
Recommended Posts