在FOR循环中访问多个数组

时间:2019-05-03 14:03:38

标签: batch-file

我需要为RS_NAME []中的每个值运行“ create.exe”。

“ create.exe”所需的参数之一是FILE_CONFIG [],该参数应对应于RS_NAME []-> RS_NAME [0]的FILE_CONFIG [0]

我无法弄清楚如何正确地将相应的FILE_CONFIG []值传递给CALL命令。我试图使用另一个FOR循环无济于事。

任何帮助将不胜感激。谢谢!

SETLOCAL EnableDelayedExpansion
@echo off
...
...
SET RS_NAME[0]=Application1
SET RS_NAME[1]=Application2
SET RS_NAME[2]=
SET RS_NAME[3]=

REM FILE_PARAMS[0] corresponds to RS_NAME[0] and so on.

SET FILE_CONFIG[0]=C:\Users\Administrator\Desktop\Application1Params.xml
SET FILE_CONFIG[1]=C:\Users\Administrator\Desktop\Application2Params.xml
SET FILE_CONFIG[2]=
SET FILE_CONFIG[3]=

For /F "tokens=2 delims==" %%s in ('set RS_NAME[') do ( 

   ::  Displaying all information and writing it to "LOGFILE"
   call %PATH_TO_EXEC%create.exe -action info -user %USER% -pass %PASSWORD% 
   timeout %TIMEOUT% >>%LOGFILE%

   :: Finding "RS_NAME" in the "LOGFILE" and if not present, then create one    
   findstr /m %%s %LOGFILE%
   if !errorlevel!==0 (
    echo ### ------ERROR------### RS_NAME ### %%s ### ALREADY EXISTS
    exit /b
        )
   if !errorlevel!==1 (
       call %PATH_TO_EXEC%create.exe -action create -name %%s -fileconfig 
       %FILE_CONFIG% -version %VERSION% -type %TYPE% -user %USER% -pass 
       %PASSWORD% -timeout %TIMEOUT%
       if !errorlevel! neq 0 (
       echo ### ------ERROR------ ### Failed to create resource: %%s. 
       exit /b !errorlevel! 
       )
       if !errorlevel! equ 0 (
       echo ### ------SUCCESS------ ### Created Successfully 
       )
     )

)

0 个答案:

没有答案