Shamik
Shamik

Reputation: 1609

How to get the current version of jre installed using batch file

Well I am writing a batch file where i need to get the current version of the installed jre in my system and then make a decision based on that- I am aware that i can get the current version by querying the registry. The following command gives the below output-

reg query "HKLM\Software\JavaSoft\Java Runtime Environment"

HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment
    Java7FamilyVersion    REG_SZ    1.7.0
    CurrentVersion    REG_SZ    1.7

HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\1.7
HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\1.7.0

But i am unable to get the value 1.7 parsing this output using the

for /f "tokens=3"  %%i in ('Command') do echo %%i

I want only the "1.7" specific to the current Version and then compare it and make a decision. I am not able to understand what option will get that. Anyone good in batch commands can please help me out on this ? Any help will be appreciated. I also tried to parse the output of java -version and get the value.

Upvotes: 0

Views: 1169

Answers (1)

mihai_mandis
mihai_mandis

Reputation: 1658

You can use the "java -version" command and filter/parse the output.

rem Taking "java -version" output and filter the line containing "Runtime Environme nt". Taking the the 6th word and echo the part before "_"

for /f "tokens=1-10" %%a in ('java -version 2^>^&1 ^| find "Runtime Environme
nt"') do for /f "delims=_" %%x in ('echo %%f') do echo %%x

Upvotes: 2

Related Questions