I'm trying to parse a variable. Say NAMELIST = "AAA BBB CCC" and store each one as a variable. Then, these new variables must be used in another command. Eg:
perl.exe C:\action.pl <VAR1>
perl.exe C:\action.pl <VAR2>
perl.exe C:\action.pl <VAR3>
I'm new to Windows Batch so any help would be appreciated.
I am aware of this thread but don't fully understand the solution
Windows batch files: How to set a variable with the result of a command?
When you refer to "store each one in a variable", the involved concept here is array. You may split the words of NAMELIST variable into 3 array elements this way:
This way, you may use each array element directly:
Or, in a simpler way using a loop:
EDIT: You may use this method with an unlimited number of values in the NAMELIST variable, just use the previous value of %i% instead the 3 (better yet, change it by "n"). I also suggest you to use the standard array notation this way:
VAR[%%i]
:Variables in batch can be set by using for loop. I'll try to explain the example given in the link.
Here For /F is used to break up the output into tokens. "delims=" means no explicit separator is given so "space" is assumed. %%a is like index variable of loop however instead of traditional index variable in programming languages where index variable has a numeric value index variables in batch can store the tokens i.e. output of command. set command then sets the variable "theValue" to %%a which holds the output/token of the command. Thus if the statement is:
You can specify your own separator as per your requirement. Hope this helps!