I need to fetch java version 1.6.0_26
from the below java -version
output
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)
Please help me getting 1.6.0_26
Note: I don't need power shell or any external programs
UPDATE
I came up with java -version 2>&1 | findstr /i "version"
which give me below output
java version "1.6.0_22"
now even a java way of pattern matching or regex will work for me :)
You can run the solution from the question Pangea linked to in a single line:
c:\>for /f "tokens=3" %g in ('java -version 2^>^&1 ^| findstr /i "version"') do @echo %g "1.6.0_24" c:\>for /f "tokens=3" %g in ('java -version 2^>^&1 ^| findstr /i "version"') do ( @set v=%g & @echo %v:~1,8% ) 1.6.0_24
I just checked and it seems my second example only works with Windows7, the following works for me on Windows XP (so it should work on Windows7 as well)
for /f "tokens=3" %g in ('java -version 2^>^&1 ^| findstr /i "version"') do ( @echo %~g )
you can do it from single line from command promt C:>java -version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With