In my Windows batch file I have some variable with a various number of strings.
For exapmle:
set string="-start" "-end someOption"
I count the numbers of a String the following way:
Set count=0
For %%j in (%string%) Do Set /A count+=1
echo.Total count: %count%
The output would be:
Total count: 2
Now I want to start an application as many times as I have Strings in my variable and I want to give the application the current string as parameter. I tried this:
FOR /L %%H IN (1,1,%COUNT%) DO (
echo %%H
FOR /F "tokens=%%H " %%I IN ("%string%") Do (
echo %%I
rem java -jar app.jar %%I
)
)
But unfortunately this does not work: Thats the output:
Number of current String: 1 “%H “” kann syntaktisch an dieser Stelle
nicht verarbeitet werden. (%H “” can not be used syntacticaly at this
place) Number of current String: 2 “%H “” kann syntaktisch an dieser
Stelle nicht verarbeitet werden.
How can I loop through the two Strings in my variable “string”?
You can’t use a FOR-parameter nor a delayed expanded variable at the option field of
FOR/F.But you can create a function and use there percent expansion.
The splitting is an effect of the delim characters, it’s per default space and tab, and they work also in the quoted parameter.
So I changed your delimiter to a semicolon, then it works.