3

This isn't very googleable, and other than writing prog.exe -params several times in a batch file (which would obviously only work as many times as I wrote it) I can't think how to repeatedly do this.

The CLI program I'm running sometimes crashes. I don't want to manually restart it every time it does.

OJFord
  • 641

4 Answers4

5

Perhaps just write the command in the batch once, and then also add the batch file to the batch itself (so it loops)...

Something like:

Go.bat:

@echo off
Prog.exe -params
Go.bat

Hit Ctrl-C when you want to break the batch loop.

3
:main
@start /wait prog.exe -params
goto :main
0

I actually decided to use C in the end, as I had trouble with the batch file opening infinite instances :/

Here's a very simple alternative in C for anyone interested:

int main(){
    while (1){
        system("C:\\path\\to\\prog.exe -params \"param vars\"");
    }
}

By default, system() requires the command or process to finish or return before the next line is executed (If you don't want this behaviour, add & at the end) - which is exactly what we want in this instance.

If prog.exe closes, we look at the next line of C, which since this is an infinite while loop, reopens the program.

OJFord
  • 641
-1

IF program closes on crash you can detect if its running or not.

(You can check if its running and run it if need be - you can loop the check at interval)

https://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script

IF the program doesn't close on crash: Short of coding a custom program to do it you can use a Macro recorder with image recognition to execute whatever action you want when it recognizes an event you specify.

However this gets complicated if you want to actively work on the machine while this process is running. You might as well just make a quick-launch shortcut for it and click once manually per crash. The other options are just good if you AFK and you want to make sure it re-runs in your absence.

helena4
  • 378