How to get java version and want to get '6' out of java version from batch file. I tried below script, but it 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 FilesJavajdk1.6.0_31"
ECHO java installed successfully
) 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%in
for /f tokens^=2-5^ delims^=.-_^" %%j in ('%JAVA_HOME%/bin/java -version 2^>^&1') do set "jver=%%j%%k%%l%%m"
echo %jver%
JAVA_HOME has "C:Program FilesJavajdk1.6.0_31" value.
See Question&Answers more detail:os