I run a bat file to clean up and sometimes it takes a few seconds for my app to full close. In it i delete a database. Instead of waiting or running it multiple times i would like the bat file to continue its attempts until it has a success. How can i do that?
+3
A:
goto :foo2
:foo
sleep 1
:foo2
del file
if exist file goto :foo
jeffamaphone
2010-05-21 23:35:18
Your users will hate you for using so much CPU
Earlz
2010-05-21 23:42:35
+1 to the answer because it's correct. +1 to @Earlz because he's also correct. Perhaps a sleep command will help. That or running the batch file at a lower priority.
afrazier
2010-05-21 23:45:03
Well, okay, I assumed this was for your own personal machine in the course of development. You shouldn't ship this.
jeffamaphone
2010-05-21 23:53:48
Note: I edited your answer. You may want to rollback or tweak it to your liking. Anyways, good answer.
acidzombie24
2010-05-22 06:17:35
ping'ing localhost is probably the best way to sleep on NT systems, on 9x you also have choice.com
Anders
2010-05-22 12:59:46
A:
In this code, you rely on the fact that your command sets non zero error level if (when) it fails. And you know which error code it sets.
Something along the lines of
@echo off
:Delete
deletedatabasecommand
if ERRORLEVEL 123 GOTO Delete
That should do it.
mr.b
2010-05-21 23:39:05