Welcome Guest! To access all forums & features, please register an account or sign-in. → Why register?



Extracting Java Version via CMD


1 reply to this topic - - - - -

#1 +CPressland

    cpressland.com

  • 6,761 posts
  • Joined: 16-September 06
  • Location: England
  • OS: OS X Mountain Lion

Posted 17 January 2013 - 10:24

Hey,

I'm currently working on migrating versions of Java to the latest build and am currently trying to do some custom reporting back to my Inventory Server; currently on OS X I'm running a shell script which looks like this:

/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version 2>&1 | grep "java version" | awk '{print $3}' | sed -e "s/\"//g"


This exports code which looks like this:

Attached Image: Screen Shot 2013-01-17 at 10.22.03.png

So what I need is a Batch Script which will do the exact same on Windows. Any ideas?


#2 OP +CPressland

    cpressland.com

  • 6,761 posts
  • Joined: 16-September 06
  • Location: England
  • OS: OS X Mountain Lion

Posted 18 January 2013 - 15:45

Just in case anybody in the future needs this:

@echo off
setlocal

set VERSION6="1.6.0_21"
for /f "tokens=3" %%g in ('java -version 2^>^&1 ^| findstr /i "version"') do (
set JAVAVER=%%g
)
set JAVAVER=%JAVAVER:"=%
@echo %JAVAVER%
endlocal
@exit %JAVAVER%