在我的batch file中,我有以下variables:
set collection=collection1 set environment=oracleDev set processChain1=-help,-startimport %environment% %collection%
正如您所看到的,我的进程链包含两个以“,”分隔的string。
现在我想要计算两个string(以后可能会多一个string)。 我尝试过:
Set count=0 For %%j in (%%processChain1%%) Do Set /A count+=1 echo %count%
循环/定时器在C
从`find`循环文件名?
在读取行时,awk $行带有多个分隔符
重复循环每'x'毫秒
在计算string之后,我想用每个参数(来自variablesprocessChain1的string)启动一个应用程序,我试着用:
FOR /L %%G IN (1,1,%count%) DO ( FOR /F "tokens=%count% delims=," %%H IN ("%processChain1%") DO java -jar App.jar %%H )
现在这个不能正确的工作,因为第一个错误,柜台是错的。 但我认为如果我能解决第一个问题,第二个问题应该可以正常工作。 它是否正确?
可执行while循环:没有这样的文件或目录
显示与fork分叉的进程数
批处理脚本 – 当另一个批处理完成时打破循环
使用bash脚本遍历包含域的文本文件
Linux命令行使用for循环和格式化结果
据我所知,现在正在计数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结构来分隔空间值(默认的分隔符),并把每个变量放在引号中…至少它的工作原理,并给你总数。
当然只有这样才能使用它。
希望能帮助到你。 干杯。
如果不是,请看看这里,也许是帮助: 在批处理文件中分离令牌
祝你好运
编辑2 (匹配新信息)
@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
祝你好运哥们;-)
在这里,我要提出我的解决方案,但gmo的解决方案至少和我一样好。
@echo off rem !!!!!!!!!!!!!!!!!!!!! rem Set Parameter options rem !!!!!!!!!!!!!!!!!!!!! set collection=collection1 set environment=oracleDev rem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! rem Set modulees As Parameters rem Watch out: Each module + his options has to be in quotation marks rem Options are separated by comma without whitespaces rem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! set helpmodule="-help" set importmodule="-startimport,%environment%,%collection%" rem !!!!!!!!!!!!!!!!!!!!!!! rem Configure Process Chain rem !!!!!!!!!!!!!!!!!!!!!!! set activeProcessChain=%helpmodulee%,%importmodule% rem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! rem Start Content Integration Testing Framework rem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Set count=0 For %%j in (%activeProcessChain%) Do Set /A count+=1 FOR /L %%H IN (1,%COUNT%) DO ( call :loopThroughParams %%H ) exit /b :loopThroughParams FOR /F "tokens=%1 delims=," %%I IN ("%activeProcessChain%") Do ( echo. echo. java -jar %nameOfApplication% %%~I ) exit /b :end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。