PDA

View Full Version : Python version and cut



LocutusOfBorg
25th August 2007, 05:16 PM
If I do

python -V | cut -f2 -d' '
or

python -V | sed 's/Python\ //'
I get

Python 2.5
instead of

2.5
With another program,say ogminfo, it works as expected:

ogminfo -V | cut -f2 -d' '
or

ogminfo -V | sed 's/ogminfo\ //'
gives

v1.5
Somebody knows why?

RupertPupkin
25th August 2007, 06:50 PM
That happens because, for some very strange reason, the output of "python -V" is going to stderr, not stdout. Since cut is expecting input from stdout, it never even sees that python version output. You can send stderr to stdout, so that cut can read it, like this:

python -V 2>&1 | cut -f2 -d' '
That shows just "2.5" on my F7 system. I'm guessing that the Python developers deliberately did that to confuse people, they have a wacky (Monty Pythonesque) sense of humor. :)

LocutusOfBorg
25th August 2007, 07:05 PM
Many thanks! :)