Solved Extract data from a multi-line command output

Hewlett-packard / Pavilion hpe
February 4, 2015 at 07:36:19
Specs: Windows 7 Professional x64, 3.6GHz 16GB
I want to exctract the version string which is output when entering "Java -version" in the command prompt.
The output is:

java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-bit Server VM (build 24.75-b04, mixed mode)

To extract it, I tried using this:

for /f "tokens=1,2,3 delims= " %%A in ('Java -version | findstr /x /i "java version "') do (
set %%A=%%B
set %%B=%%C

However, this returned "| was not expected"

What am I doing wrong?

If infinity is infinite, is the square root of infinity infinite as well?
- Kurp Von Steiner

See More: Extract data from a multi-line command output

Report •

February 4, 2015 at 08:10:40
✔ Best Answer
::====== script starts here ===============
:: java -version writes to stderr NOT stdout
:: RainBaw.bat 2015-02-04 22:58:09.65
@echo off & setLocal enableDELAYedeXpansioN

java -version 2>jout
set /p jver=<jout
echo !jver!
del jout
::====== script ends here =================

M2 Golden-Triangle

Report •
Related Solutions

Ask Question