0

I am essentially looking for this solution 'timeout a command in bash without unnecessary delay', but it must be for a script.bat file.

Given a cmd.exe terminal. And we start "long-running" /path/to/long-running program. And we set a timeout /t 600 /nobreak to give the program time to run. After which we taskkill /F /FI "WINDOWTITLE eq long-running" to stop the program.

When the program ends earlier than 600s, say after 120s.

Then the script must terminate early without waiting for the timeout to reach 600s.

How can we terminate the script at the earlier of the two? [ timeout elapsed / early termination ]

avanderw
  • 675
  • 1
  • 7
  • 22
  • 1
    You would not be able to use the `TIMEOUT` command. You would need to create a loop to keep checking every few seconds if the program is running and/or if the timeout value has been reached. – Squashman Sep 23 '20 at 15:45
  • If all your doing is waiting for the program to close, what's wrong with `start /wait ...` – T3RR0R Sep 23 '20 at 17:40
  • Think of a server that runs as a daemon but you have a memory leak in and restarting it every x seconds is acceptable. However, it might crash for any other reason as well. How do you know when to restart the server? Polling as @Squashman suggested is likely the only solution I can see. – avanderw Sep 23 '20 at 19:23

0 Answers0