据我所知,现在计数为 1,因为该 var 中只有一个字符串,稍后您将进行拆分,但您的令牌计数已设置为 1....
您需要拆分第一个字符串 (delims=,),然后在第二部分中处理每个结果。
编辑:
试试这个...
@echo off
set collection=collection1
set environment=oracleDev
set processChain1="-help" "-startimport %environment% %collection%"
Set count=0
For %%j in (%processChain1%) Do Set /A count+=1
echo.Total count: %count%
pause
如您所见,我更改了 var processChain1结构以用空格(默认分隔符)分隔值并将每个 var 放在引号中......至少它有效,并为您提供总数。
当然,如果你能以这种方式使用它。
希望能帮助到你。干杯。
如果没有..看看这里,也许有帮助:批处理文件中的单独标记
祝你好运
EDITED 2(匹配新信息)
批处理文件:Metalhead89.bat
@echo off
:: define the vars
set collection=collection1
set environment=oracleDev
:: concatenate the vars with ++
set processChain1=-help -startimport++%environment%++%collection%
:: Get the total count plus, run each token found
Set count=0
For %%j in (%processChain1%) do (
Set /A count+=1
set line=%%j
call :processToken
)
:: This will be printed out, at the end of the loop
echo Total token count: %count%
goto :eof
:processToken
for /f %%f in ("%line%") do (
:: set the command var with your exe file for each token found
set command=Running command: java -jar app.jar %%f
call :runTheCommand
)
goto :eof
:runTheCommand
:: now we replace the doble ++ in the var string with space, to treat them as options
set str=%command%
set str=%str:++= %
:: finally we do a echo of the command with the option included
echo %str%
goto :eof
现在,从命令行调用该文件,您将获得:
Z:\>call Metalhead89.bat
Running command: java -jar app.jar -help
Running command: java -jar app.jar -startimport oracleDev collection1
Total token count: 2
祝你好运哥们;-)