Solved Set result of command(multiple lines) to variable

October 10, 2012 at 07:19:40
Specs: Windows 7
I've noticed when using for /f "delims=" %%a in ('randomcommand') do set result=%%a
if the result has multiple lines, only the first line is parsed.
How will i be able to set all the result to the variable?

See More: Set result of command(multiple lines) to variable

Report •


✔ Best Answer
October 10, 2012 at 16:52:48
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

SET RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
FOR /f "delims=" %%A IN ('REG.exe Query %RegQry%') DO (
    SET result=!result!%%A
)

ECHO Result = "!result!"

EXIT /B

When your only tool is a hammer, every problem looks like a nail.



#1
October 10, 2012 at 07:43:22
Depending on the command, It would make sense that it would only set the first, as that's what %%a should be. The first piece of data before the delim( <space> or <tab>) depending on how windows 7 interprets it.

What is the command you are working with?

:: mike


Report •

#2
October 10, 2012 at 08:08:30
if the result has multiple lines, only the first line is parsed.
Incorrect. All lines are parsed, but only the last line of non-blank output is saved. What is your goal?

How To Ask Questions The Smart Way


Report •

#3
October 10, 2012 at 08:24:06
@Razor

Just because I have never tried it, always used "delims=*" to set the whole line, does delims=" do the same?

:: mike


Report •

Related Solutions

#4
October 10, 2012 at 09:24:07
"delims=*" tokenizes the string on asterisks. "delims=" returns the entire line as a single token.

How To Ask Questions The Smart Way


Report •

#5
October 10, 2012 at 09:27:04
I see, thanks for the info, always good to know I have been doing it wrong :D

:: mike


Report •

#6
October 10, 2012 at 11:03:44
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0

REG.exe Query %RegQry% > checkOS.txt
instead of extracting the output to the .txt file i want the result which in my case is:

HKEY_LOCAL_MACHINE\Hardware\Description\System\CentralProcessor\0
Component Information REG_BINARY 00000000000000000000000000000000
Identifier REG_SZ x86 Family 6 Model 15 Stepping 11
Configuration Data REG_FULL_RESOURCE_DESCRIPTOR FFFFFFFFFFFFFFFF0000000000000000
ProcessorNameString REG_SZ Intel(R) Core(TM)2 Duo CPU T7500 @ 2.20GHz
VendorIdentifier REG_SZ GenuineIntel
FeatureSet REG_DWORD 0xa08f3fff
~MHz REG_DWORD 0x892
Update Status REG_DWORD 0x0
Update Signature REG_BINARY 00000000B6000000
Previous Update Signature REG_BINARY 0000000000000000
Platform ID REG_DWORD 0x80

to be parsed to the variable.
for /f "delims=" %%a in ('REG.exe Query %RegQry%') do set result=%%a
only sets the first line to the variable.


Report •

#7
October 10, 2012 at 16:52:48
✔ Best Answer
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

SET RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
FOR /f "delims=" %%A IN ('REG.exe Query %RegQry%') DO (
    SET result=!result!%%A
)

ECHO Result = "!result!"

EXIT /B

When your only tool is a hammer, every problem looks like a nail.


Report •

#8
October 10, 2012 at 20:06:23
Orangeboy, appreciate your help, this does exactly what i was aiming for:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

SET RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
FOR /f "delims=" %%A IN ('REG.exe Query %RegQry%') DO (
SET result=!result!%%A
)

ECHO %result%
pause > nul

EXIT /B


Report •


Ask Question