Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: DOS batch scripting to identify JAVA version  (Read 4395 times)

0 Members and 1 Guest are viewing this topic.

dc1777

  • Guest
DOS batch scripting to identify JAVA version
« on: January 02, 2008, 09:52:59 PM »
good day. I'm kinda new here. I want to ask if is there a way for a batch (.bat) file to retreive and parse the message of a java command (say "java -version").

then later on identify the type of version it reflected through a nested if statement? (e.g. if ERRORLEVEL == "1.4.2_12 goto lower).

I would appreciate if somebody could help me out with these.
Thank you very much.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: DOS batch scripting to identify JAVA version
« Reply #1 on: January 03, 2008, 04:11:53 AM »
I was able to redirect the STDERR stream to a file. For whatever reason, java did not seem to output to STDOUT.

Code: [Select]
@echo off
java -version 2> java.txt
for /f "tokens=3" %%x in ('find /i "java version" java.txt') do (
if %%~x==1.6.0_03 goto label3
if %%~x==1.6.0_02 goto label2
if %%~x==1.6.0_01 goto label1
if %%~x==1.4.2_12 goto label0
)
.
.
.
del java.txt

 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein