I am trying to tidy a batch file up so that it will attempt the connection to the database before launching the webserver, if it fails it will attempt again up to 5 times but if connection is ok will move on to lauching webserver. I was hoping something i'd seen in another post might suffice but i'm completely new to batch files. @echo & setLocal EnableDELAYedeXpansion
if %1'==' echo how many && goto :errormsg
set /a N=%1
:1
:: 30s
sqlplus user/pswd@localhost/XE
set /a N-=1 && if !N! equ 0 goto :startwebsvr
if errorlevel 1 goto :1I don't want to go down creating 5 entries for each attempt i.e :retry1 :retry2 etc
Many thanks
untested =====================================
@echo off & setLocal EnableDELAYedeXpansionset /p N=how many ?
for /L %%i in (1 1 !N!) do (
sqlplus user/pswd@localhost/XE
if not errorlevel 1 goto :start
)
goto :eof
:start
:: the work gets done here
=====================================
Life is too important to be taken seriously.M2
Thanks for the great response Mechanix, i took out the user prompt and set it to repeat 5 times, tested on my machine as i knew it would create the error and works ok.
Would it be simple to add a delay inbetween the retries or would this need a bit code change?
Also, if i add this code into a larger batch file will i need to add endlocal?@echo off & setLocal EnableDELAYedeXpansion
for /L %%i in (1 1 5) do (
sqlplus user/pswd@localhost/XE
if not errorlevel 1 goto :start
)
goto :errormsg:start
pause (just for testing)
:errormsg
msgbox Application failed to load - Please call the helpdesk
Think i've got it, used wait32.exe and works great, probably not the best way but working. @echo off & setLocal EnableDELAYedeXpansion
for /L %%i in (1 1 5) do (wait32.exe /s30
sqlplus user/pswd@localhost/XE
if not errorlevel 1 goto :start
)
goto :errormsg
:start
pause:errormsg
msgbox Application failed to load - Please call the helpdesk
With 30 sec delay CALLed as a sub. Don't leave out either goto :eof or it will lose the plot. ===========================================
@echo off & setLocal EnableDELAYedeXpansioncall :sub1
:main
echo other tasks here
goto :eof:sub1
for /L %%i in (1 1 3) do (
sqlplus user/pswd@localhost/XE
if not errorlevel 1 goto :start
ping 1.1.1.1 -n 1 -w 30000 > nul
)
goto :eof
:start
:: the work gets done here
goto :eof
=====================================
Life is too important to be taken seriously.M2
Hi Mechanix2go, Thanks for the great info again, just a couple of questions on this.
Will the :eof in either of these close the batch file or just signal the end of that action? from what i've read i believe it ends the batch file but still a little unclear.
I want to call the errormsg batch file should all attempts at connecting to the database fail, is it possible to incorporate?
I should point out that in the example of what i was using above the full batch file did have EXIT at the end to close it once complete.
just signal the end of that action
=====================================
Life is too important to be taken seriously.M2