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

2
  • Possible duplicate of How to get Java Version from batch script? Commented Mar 16, 2018 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. Commented Mar 16, 2018 at 11:13

1 Answer 1

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**" 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.