Solved Batch File Counter Increment

September 10, 2008 at 11:02:40
Specs: XP, 1.7 ghz/2 gig
Is it possible to increasement an integer counter in a batch file script? Example:

Set Sleep=0
:Rerun
osql ...
if %ERRORLEVEL%==0 goto :Cont
Set Sleep=%Sleep%+1
if %Sleep%==3 goto :ErrorOut
goto :Rerun
:ErrorOut
exit %ERRORLEVEL%
:Cont
...

Basically, I need to run a SQL Server Stored Procedure until it successfully runs before I want the script to error out. Currently, the result for %SLEEP% will be '0+1' after the code above runs, not 1. Can anyone help?


See More: Batch File Counter Increment

Report •


#1
September 10, 2008 at 11:38:09
✔ Best Answer
Rewrite your code as below

Set Sleep=0
:Rerun
osql ...
if not ErrorLevel 1 goto :Cont
Set /A Sleep+=1
if %Sleep% lss 3 goto goto :Rerun
exit %ErrorLevel%
:Cont
...


Report •

#2
September 10, 2008 at 14:30:30
Worked like a charm. I love it when there are people smarter then I am out there that don't mind helping out. Thanks!!

Report •

Related Solutions


Ask Question