0

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

BV45
  • 605
  • 3
  • 10
  • 27
  • Possible duplicate of [How to get Java Version from batch script?](https://stackoverflow.com/questions/5675459/how-to-get-java-version-from-batch-script) – A. Bandtock Mar 16 '18 at 10:54
  • Not quite. I am trying to modify that script to get just one output, but it is bringing back an empty row and (). The other script did not have that. – BV45 Mar 16 '18 at 11:13

1 Answers1

0

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**" 
BV45
  • 605
  • 3
  • 10
  • 27