开发者

DOS script to check if the default java installed version is greater than 1.x

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 va开发者_JAVA百科lue 1.x.

Anyone can help me?

Thanks!


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


if you can download and gawk for windows.

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


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.


In commmand prompt you can just type it has java -version.

For example:

D:\Users> java -version 

then you will get the answer as

java version 1.8.0_11
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜