Time limit on executable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Posts: 2
Joined: 19 Jul 2012 08:30

Time limit on executable

#1 Postby emuell02 » 19 Jul 2012 09:09

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.


Posts: 2851
Joined: 23 Dec 2011 13:59

Re: Time limit on executable

#2 Postby Squashman » 19 Jul 2012 09:19

So use TASKLIST to see if it is still running. If it isn't then run the next step.

Posts: 2
Joined: 19 Jul 2012 08:30

Re: Time limit on executable

#3 Postby emuell02 » 19 Jul 2012 09:31

How would I go about using TASKLIST simultaneously with the ping command?
And then how would I halt the ping command?

Posts: 5177
Joined: 10 Feb 2012 02:20

Re: Time limit on executable

#4 Postby foxidrive » 19 Jul 2012 10:39

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.

Return to “DOS Batch Forum”

Who is online

Users browsing this forum: Aacini, Baidu [Spider], Google [Bot], Yahoo [Bot] and 4 guests