views:

37

answers:

3

As the subject said, i need a dos script to check the version of java installed on windows xp Machine. Furthermore, I need to check if the version is greater than a prefixed value 1.x.

Anyone can help me?

Thanks!

A: 
java -version

You can also use the command

java -fullversion

and produce output such as:

java full version "1.6.0_17-b04"

On a computer without any version of Java from Sun Microsystems installed, this results in an error message:

'java' is not recognized as an internal or external command, operable program or batch file.

In a batch you could do:

@echo off
java.exe -fullversion 2> c:\temp\out.txt
for /F "tokens=4" %%i IN (c:\temp\out.txt) DO echo %%i  

You can't avoid the temp file because the java.exe output writes on the standard error! So you have to redirect the standard error to a file.

vulkanino
+2  A: 

Getting the version, and write it into a temp file. Then only parse the version itself:

@echo off
echo off
java -version 2> tmp_java_version.txt
set /p JAVA_VERSION= < tmp_java_version.txt
del tmp_java_version.txt
set JAVA_VERSION=%JAVA_VERSION:~14,3%

echo %JAVA_VERSION%
pause > NUL
Keenora Fluffball
nice. you can avoid the temp file if you use the for command
Preet Sangha
It can be the case where java is not set in path but installed.
org.life.java
Afaik, if Java is installed, there is also a java.exe in the System32 directory, which means, java can be called from every position in the shell. Therefore there shouldn't be a problem. Maybe the var is empty, but you have to check it anyway.
Keenora Fluffball
A: 

if you can download and gawk for windows.

C:\test>java -version 2>&1 | gawk "NR==1{print $3}"
"1.6.0_16"
ghostdog74