Petit stray Python version output

wrap up

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 ....

Details

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

Impressions

If you straddle multiple environments, you'll get frustrated with Shell games!

What if you want the result with the same command?

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

Petit stray Python version output
[Code] Module and Python version output
python learning output
PYTHON2.7 64bit version
Python version check V outputs standard error output
python input and output
Python audio input / output
Output python execution time
Japanese output in Python
Python version switching (pyenv)
Basics of python: Output
Check version with python
Try Python output with Haxe 3.2
Breadth-first search / bidirectional search (Python version)
Change python version using pyenv
Version upgrade of python Anaconda
Python version does not switch
Check OpenSSL version of python 2.6
Introduction to Python (Python version APG4b)
How to change Python version
Specify python version with virtualenv
tesseract-OCR for Python [Japanese version]
Read Fortran output in python
Error resolution python version check
[Python] Tuple version of prefecture pull-down
Output 2017 Premium Friday list in Python
Tips on Python file input / output
Anaconda and Python version correspondence table
Install xgboost (python version) on Windows
Output to csv file with Python
[Python] Variable (definition, output, value change)
pyenv-change the python version of virtualenv
Self-organizing map in Python NumPy version
Ideone> Python version: 3.5 (as of August 29, 2017)
Make standard output non-blocking in Python
How to get the Python version
Change the Python version of Homebrew
Master linear search! ~ Python implementation version ~
[Note] Hello world output with python
Unit test log output with python
Have python read the command output
Notes for Python file input / output
[2021 version] Python installation Windows 10 (64bit) edition
Export and output files in Python
Manage each Python version with Homebrew
Faster Fibonacci sequence calculations (Python version)
Interactively output BPE using python curses
Python version to get unused ports
[AWS SAM] Introduction to Python version
[Python Windows] pip install with Python version