Reputation: 671
I have hard times with implementation of this script. Have no idea why it iterates only once, when it "should" at least 3. I have found some similar problems on SO so I guess i dont understand something. When IF !ERRORLEVEL! equ 0
condition is fulfilled it prints and echo
and exits script and my expected behavior is to iterate 2 more times. Does someone know the reason and could help me with this a little?
set "modules=Module1 Module2 Module3"
SETLOCAL ENABLEDELAYEDEXPANSION
for %%i in (%modules%) do (
set moduleName=%%i
@echo Running !moduleName! module...
set "moduleBootRunName=!moduleName:~6,1!"
call :tolower moduleBootRunName
set "moduleBootRunName=!moduleBootRunName!!moduleName:~7!"
copy NUL > %logsTmpFile%\!moduleName!.txt
start cmd /c "gradlew :modules:!moduleBootRunName!:bootRun --info > %logsTmpFile%\!moduleName!.txt"
:waitForModule
findstr /c:"Started !moduleName!" %logsTmpFile%\!moduleName!.txt > NUL
IF !ERRORLEVEL! equ 0 (
@echo Started !moduleName!
) ELSE (
@echo Waiting for !moduleName!...
timeout /t 5 > NUL
goto waitForModule
)
)
exit /b
:tolower
for %%L IN (a b c d e f g h i j k l m n o p q r s t u v w x y z) DO SET %1=!%1:%%L=%%L!
goto :EOF
Upvotes: 1
Views: 44
Reputation:
Untested
set "modules=Module1 Module2 Module3"
SETLOCAL ENABLEDELAYEDEXPANSION
for %%i in (%modules%) do (
set moduleName=%%i
@echo Running !moduleName! module...
set "moduleBootRunName=!moduleName:~6,1!"
call :tolower moduleBootRunName
set "moduleBootRunName=!moduleBootRunName!!moduleName:~7!"
copy NUL > %logsTmpFile%\!moduleName!.txt
start cmd /c "gradlew :modules:!moduleBootRunName!:bootRun --info > %logsTmpFile%\!moduleName!.txt"
call :waitForModule
)
exit /b
:tolower
for %%L IN (a b c d e f g h i j k l m n o p q r s t u v w x y z) DO SET %1=!%1:%%L=%%L!
goto :EOF
:waitForModule
findstr /c:"Started !moduleName!" %logsTmpFile%\!moduleName!.txt > NUL
IF !ERRORLEVEL! equ 0 (
@echo Started !moduleName!
) ELSE (
@echo Waiting for !moduleName!...
timeout /t 5 > NUL
goto waitForModule
)
Upvotes: 3