Solved Pull Multiple Lines into Text File

August 10, 2009 at 15:03:29
Specs: Windows XP
So.. I'm having a bit of trouble with something that I thought would be relatively simple.

I'm trying to collect the Java version from a number of computers with a login script, and write that information to a txt file.

I'd like to avoid using WMIC to pull and filter the result and pull the data from the "java -version" command. The problem I'm having is in actually getting that information into a text file as the command returns a multi-lined response that just won't take into a file as I had hoped.

The command returns this:

C:\Documents and Settings\username>java -version
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)


When attempting to append to a text file, I get a blank document.

Am I missing something? Is this not doable in this way? Is it due to the way the java app returns the information?


See More: Pull Multiple Lines into Text File

Report •


#1
August 10, 2009 at 21:29:53
✔ Best Answer
"Is it due to the way the java app returns the information?"

yep It writes to stderr; no idea why.

==================================
@echo off & setLocal enableDELAYedexpansion
java -version 2> #
for /f "tokens=3 delims= " %%a in (#) do (
echo %%~a >> jver.txt
del #
goto :eof
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
August 11, 2009 at 02:12:50
Good answer M2. By the way, it is possible to avoid creating a temporary file:
@echo off & setLocal enableDELAYedexpansion
for /f "tokens=3 delims= " %%a in ('java -version 2^>^&1') do (
   echo %%~a >> jver.txt
   goto :eof
)


Report •

#3
August 11, 2009 at 13:40:03
Great!!

Report •

Related Solutions

#4
August 11, 2009 at 22:41:24
Hi klint,

Yea, I figured there was a way to avoid the file but didn't know how. I knew one of you guys would show us.

;)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#5
August 12, 2009 at 08:07:23
By the way, what is the purpose of this requirement? What if someone has multiple versions of Java installed (which is perfectly possible, since when you upgrade your JDK installation that doesn't uninstall any previous versions)?

Report •


Ask Question