Loop through output of command and assign each a variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
JordanCN
Posts: 1
Joined: 20 Nov 2010 19:47

Loop through output of command and assign each a variable

#1 Post by JordanCN » 20 Nov 2010 20:02

I am trying to create a batch file to control various things on my tape library. I need to get the output of this command into variables to be used later in my batch file.

The command is:

rsm view /tphysical_media /guiddisplay /b

And the output is 7 GUIDs that can change every time I add a tape to the library. The output now is:


<< blank line >>
44519C3DB47049319158A22BC2936143
CDA50F31773143499B4E9AE2ECC965BD
D65B80646F594AA9BE247909B7396197
801387E8AC574B288A5A553130E46A5B
11662170187945F7B9CA75F54863A7E1
266A95DE022140D1BC71684A385A6B19
94A245DA463E4A5FB1E47786CA691F8F


I need skip the first blank line and loop through this output and assign each of these 7 items to a variable (Like Tape1, Tape2, Tape3, etc.).

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Loop through output of command and assign each a variabl

#2 Post by !k » 21 Nov 2010 03:05

Code: Select all

@echo off
setlocal enableextensions
set /a cnt=0
for /f %%s in ('rsm view /tphysical_media /guiddisplay /b') do (
set /a cnt+=1
call set Tape%%cnt%%=%%s
)
set Tape
pause

Post Reply