1.

Solve : I need a subroutine to tell me the installed version of java?

Answer»

Hi group,

A co-worker is updating a wrapper script for a java PROGRAM. She asked me to provide a function to tell her the installed java version because her app needs java 1.6. So, I need a little subroutine that will parse the output of 'java -version' in to a normalized version string, like '1.5', 1.6', etc.

This is no doubt a dead simple problem EXCEPT I'm a Unix guy who doesn't know MSDOS at all and doesn't have the day or two it WOULD take me to wrap my head around a new scripting language.

If anyone is feeling charitable and wants to bang one out for me, I would be forever grateful.

Thanks

Larryfret not. You can enjoy the power of Unix also on windows. Try downloading GNU win32 tools. The tool you are LOOKING for would be grep/awk.
If you can't do that, you can USE Windows own findstr/find. Just pipe the Java command "java -version" to findstr/find. Use cmd.exe's for loop to capture the output. type for /? on the command line to see how to use for loopFor whatever reason, the output of the java -version command does not go to stdout but instead to stderr. This BATCH file should help without downloading anything.

Code: [Select]@echo off
for /f "tokens=3-4 delims=. " %%i in ('java -version 2^>^&1 ^| find /i "java version"') do (
if not errorlevel 1 echo %%~i.%%j
)

Good luck. Ghostdog,

Heh. Left to my own devices, I'd do exactly that (although I'd probably use Cygwin). However, that's not appropriate for something that needs to work on the customer's machine right out of the shrink wrap.

Cheers,

LarrySidewinder,

Beautiful! It would have taken me a long time to get there.

Thanks.

Larry



Discussion

No Comment Found