I am looking to try and improve a batch file I wrote a while back. In the batch file I run a command if the command runs fine I exit out of the batch file if not I wait and retry the command again.
The way I retry the command is a little bit dirty I just run the command again from another label and then another label eg retry:, retry2: ,rety3: ect. I wanted to try and see if I could pass a command to the batch file eg Retry3 this would then try and run the program 3 times and would save me having to have so many retry labels. It would get very messy if I tried to run the program 99 times until it worked correctly
@ECHO OFF
set ERRORLEVEL=
TC %1 %2 %3 %4 %5 %6 %7 %8 %9
echo %ERRORLEVEL%
IF ERRORLEVEL 1 GOTO RETRY
IF ERRORLEVEL 0 GOTO END
:RETRY
ECHO.
ECHO %1 OF %2 FAILED LOOKING TO TRY AND %1 %2 AGAIN.
WAIT 20
set ERRORLEVEL=
TC %1 %2 %3 %4 %5 %6 %7 %8 %9
echo %ERRORLEVEL%
IF ERRORLEVEL 1 GOTO RETRY2
IF ERRORLEVEL 0 GOTO END
:RETRY2
ECHO.
ECHO %1 OF %2 FAILED ANOTHER TIME LOOKING TO TRY AND %1 %2 A SECOND TIME.
WAIT 20
set ERRORLEVEL=
TC %1 %2 %3 %4 %5 %6 %7 %8 %9
echo %ERRORLEVEL%
IF ERRORLEVEL 1 GOTO RETRY3
IF ERRORLEVEL 0 GOTO END
@ECHO Off
if “%1″==”” goto usage
set p_cnt=1
set p_cnt_max=%1
shift
:main
echo Run %p_cnt%
echo TC %1 %2 %3 %4 %5 %6 %7 %8 %9
IF ERRORLEVEL 1 GOTO RETRY
IF ERRORLEVEL 0 GOTO :EOF
:RETRY
ECHO.
ECHO %1 OF %2 FAILED LOOKING TO TRY AND %1 %2 AGAIN.
sleep 2
set /a p_cnt=%p_cnt% + 1
if %p_cnt% GTR %p_cnt_max% goto :EOF
goto main
:usage
echo.
echo USAGE – %0 repetition parameter(s)
goto :EOF