Search code examples
windowscommand-promptgeneos

How to remove empty row and "()" output from Java version check script


I have a windows command line script to run to check the java version, but it is outputting two additional rows(2 & 3) I don't need. I need it only to display the Echo of Current Java Version and the Java version number(1 & 3). Can you possibly assist with how I can modify the script?

  1. Current Java Version
  2. empty row
  3. C:\Program Files \Java|jre7\bin>()
  4. "1.7.0_161"

Command being used:

C:\Windows\system32\cmd.exe /c echo Current Java Version & C:\Windows\system32\cmd.exe /c  "for /f "tokens=3" %g in ('java -version 2^>^&1 ^| findstr /i "version"') do (@echo %g)"

Output from cmd window:

cmd_window


Solution

  • I had to remove the ( ) around the echo call after "do" as shown below. That resolved my issue:

    C:\Windows\system32\cmd.exe /c echo Current Java Version & C:\Windows\system32\cmd.exe /c  "for /f "tokens=3" %g in ('java -version 2^>^&1 ^| findstr /i "version"') do **@echo %g**"