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

Author Topic: I need a subroutine to tell me the installed version of java  (Read 4106 times)

0 Members and 1 Guest are viewing this topic.

1arryb

    Topic Starter


    Starter

    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

    Larry

    ghostdog74



      Specialist

      Thanked: 27
      Re: I need a subroutine to tell me the installed version of java
      « Reply #1 on: July 08, 2010, 01:37:04 PM »
      fret 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 loop

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: I need a subroutine to tell me the installed version of java
      « Reply #2 on: July 09, 2010, 01:12:47 AM »
      For 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.  8)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      1arryb

        Topic Starter


        Starter

        Re: I need a subroutine to tell me the installed version of java
        « Reply #3 on: July 09, 2010, 05:18:31 AM »
        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,

        Larry

        1arryb

          Topic Starter


          Starter

          Re: I need a subroutine to tell me the installed version of java
          « Reply #4 on: July 09, 2010, 05:20:11 AM »
          Sidewinder,

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

          Thanks.

          Larry