cmd - Get java version from batch file -


how java version , want '6' out of java version batch file. tried below script, didn't work.

    rem check java exists using java_home system variable  if "%java_home%" == "" ( echo installing java start /w jdk.exe /s setx -m java_home "c:\program files\java\jdk1.6.0_31" echo java installed ) else ( echo checking java version goto check_java_version )  rem check java version using java_home system variable :check_java_version set path=%path%;%java_home%\bin /f tokens^=2-5^ delims^=.-_^" %%j in ('%java_home%/bin/java -version 2^>^&1') set "jver=%%j%%k%%l%%m" echo %jver% 

java_home has "c:\program files\java\jdk1.6.0_31" value.

for /f tokens^=2-5^ delims^=.-_^" %j in ('java -fullversion 2^>^&1') @set "jver=%j%k%l%m" 

this store java version jver variable , integer , can use comparisons .e.g

if %jver% lss 16000 echo not supported version 

.you can use more major version removing %k , %l , %m.this command prompt version.

for .bat use this:

@echo off path %path%;%java_home%\bin\ /f tokens^=2-5^ delims^=.-_^" %%j in ('java -fullversion 2^>^&1') set "jver=%%j%%k%%l%%m" 

according tests fastest way java version bat (as uses internal commands , not external ones find,findstr , not use goto can slow script). jdk vendors not support -fullversion switch or implementation not same 1 provided oracle (better avoid them).


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -