Page 1 of 1

Time limit on executable

Posted: 19 Jul 2012 09:09
by emuell02
I am looking to incorporate a time limit function on an executable that I am running multiple times from a batch file.

I know that I can use the "ping localhost" command to delay for a set amount of time and then "taskkill" to terminate my executable if it is still running after the delay.

However, my problem is this: Some times the executable may take only a few minutes, sometimes it will take a few hours (with 24hrs being the cut-off I wish to set). If I set the batch file to delay 24hrs before trying to kill the executable and the executable finishes after only a few minutes, the next run of the executable will not start until 24hrs have passed. I want the next run to start immediately after the previous one finishes.

As an additional note, changing the source code of the executable is not really an option for me, as it is developed by a third party and they would most likely decline to incorporate my changes.

Thanks!

Re: Time limit on executable

Posted: 19 Jul 2012 09:19
by Squashman
So use TASKLIST to see if it is still running. If it isn't then run the next step.

Re: Time limit on executable

Posted: 19 Jul 2012 09:31
by emuell02
How would I go about using TASKLIST simultaneously with the ping command?
And then how would I halt the ping command?

Re: Time limit on executable

Posted: 19 Jul 2012 10:39
by foxidrive
You'd have to create a file with a timestamp each time the program starts, and delete the file after the program has run.

A second batch file is needed to check the timestamp (if exist file check timestamp) every 2 minutes and if it reaches 24 hours then kill the task.