Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a cmd file which executes an application (exe) that can return a specific error code in some cases. This cmd is launched by the Scheduler every day.
If it failed with this specific error, I want to be able to reschedule and retry the task every 30mn up to 3 times or for the next 2 hours before giving up until the next day.

How can I pass the error code to the scheduler to have it retry automatically (if at all possible) or how can I create a new temporary fail-over scheduled task from the initial cmd?

It should run mainly on Win2003 and Win2008 servers (x32 or x64).

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

just try to run your command, wait on failure and rerun it. you can use ping to fake a sleep command (or get a sleep.exe from the resource toolkit or hack your own or use vbscript). anyway, just schedule this script daily:

@echo first try here
@if not errorlevel 42 goto end
@ping 127.0.0.1 -w 1000 > NUL

@echo second try here
@if not errorlevel 42 goto end
@ping 127.0.0.1 -w 2000 > NUL

@echo third try here
@if not errorlevel 42 goto end
@ping 127.0.0.1 -w 3000 > NUL

@echo will try again tomorrow

:end
@echo finish %errorlevel%

replace 42with the exit code your are interested in and replace -w 1000 with the time in milliseconds you want to wait between each retry.

share|improve this answer
    
That's more or less the workaround I had in mind but I am a bit concerned about leaving it ping or sleep for 30mn instead of rescheduling. Any potential drawback with pinging for a big chunk of time? –  François Jun 27 '10 at 22:20
    
i do not know. you can also grab a sleep.exe from somewhere, if that makes you feel more comfortable. –  akira Jun 27 '10 at 22:47
add comment

Use a script (batch file) to call your application and test the error code and conditionally re-execute it or exit.

Then schedule the script instead of the application.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.