In my batch file I have the following variables:
set collection=collection1
set environment=oracleDev
set processChain1=-help,-startimport %environment% %collection%
As you can see, my process chain contains two strings that are separated with a “,”.
Now I want to count the two strings (later it could be more then one string). I tried it with:
Set count=0
For %%j in (%%processChain1%%) Do Set /A count+=1
echo %count%
But there is the first mistake. It prints out 1 and not 2. Why?
After counting the strings I want to start an application with each parameter (string from the variable processChain1)
I try it with:
FOR /L %%G IN (1,1,%count%) DO (
FOR /F "tokens=%count% delims=," %%H IN ("%processChain1%") DO java -jar App.jar %%H
)
This cant work correct now because the counter is wrong because of the first mistake. But I think if I can solve the first problem, the second should work fine. Is this correct?
As far I can tell, right now, is counting 1 because there’s only one string in that var, you are making the split later, but your token count is already set to 1….
You need to split the first string (delims=,) and then in the second part, work with each result.
EDITED:
Try this…
As you can see, I change the var processChain1 structure to separate the values with a space (default delimeter) and put every var in quotes…
At least it works, and gives you the total count.
Only of course, If you can use it in this way.
Hope it helps.
Cheers.
If not.. take a look here, maybe it’s help : separate tokens in batch file
Good luck
EDITED 2 (to match new information)
Batch file: Metalhead89.bat
Now, Call that file from command line and you will get:
Good luck buddy 😉