-1

I have the following code that executes a program with the /wait flag so that the next line doesn't execute until the first process is killed.

START "" /wait "Process1.exe"
START "" /wait "Process2.exe"

The problem is that sometimes the process can error out and never end, so I would like to also implement a timeout of 5 minutes, so that if the process is still going after 5 minutes, the timeout would kill it.

Ideally, I would like to be able to use both if possible, so that if the process finishes in 2 minutes, I don't always have to wait the entire 5 minutes.

Is this possible?

Thank you!

DanBoghean
  • 85
  • 3
  • I hope, the started process is never __killed__ by Windows, but gracefully __terminates__ itself. You can run `process1.exe` in a separate command process using `start` without `/wait` and use in current command process a loop with `%SystemRoot%\System32\timeout.exe` checking for example after every 20 seconds with `%SystemRoot%\System32\tasklist.exe` if the started process running parallel terminated itself in the meantime. After 30 checks on not done termination the batch file could use command `%SystemRoot%\System32\taskkill.exe` to first try to terminate and last kill the process. – Mofi Feb 17 '18 at 17:59
  • http://idownvotedbecau.se/noresearch/ a lot of duplicates: [Taskkill with timeout in bat](https://stackoverflow.com/q/21166364/995714), [timeout or close when process is finished](https://stackoverflow.com/q/46858942/995714), [How to set a timeout for a process under Windows 7?](https://stackoverflow.com/q/13515254/995714), [How to wait and kill a timeout process in Powershell](https://stackoverflow.com/q/19532998/995714), [Powershell Start Process, Wait with Timeout, Kill and Get Exit Code](https://stackoverflow.com/q/36933527/995714) – phuclv Feb 18 '18 at 00:44
  • @Mofi That was the process that worked for me. Thank you! – DanBoghean Feb 19 '18 at 16:06

1 Answers1

0

You could start another instance which kills the process after n seconds:

START /MIN CMD /C "TIMEOUT /T 300 /NOBREAK & TASKKILL Process1.exe" & START "" /WAIT Process1.exe
FatalBulletHit
  • 762
  • 6
  • 22