1.

Solve : Command to start process once process has ended?

Answer»

Hello all,

Thanks for taking the time to LOOK into my problem. I've been messing around with MS-DOS commands but I'm not fully compatible with it yet. What I would like to do is enable an automated batch file where the file monitors for a specified process to end and re-initiate the command to START the process again if it crashes.

Below is my code THUS far:

@echo off
cls
title Crash Prevention
echo Crash Prevention enabled, opening Processor.exe...
:step1
echo (%time%) Processor.exe started.
start /wait C:\Users\Corey\Desktop\cmd\Processor.exe
echo (%time%) Restarting program due to crash.
goto step1

The only problem I have is 'Processor.exe' executes another program to open, and then Processor.exe closes (I can't run the 2nd program, it has to be done in this order). Once it closes, it goes back to :step1 and initializes the same command over and over. What I would like to do is monitor for the 2nd program once it starts and crashes instead of Processor.exe, and re-initiate the full command as seen above if it were happen to crash.

Any THOUGHTS would be greatly appreciated.

Thanks,
CoreyLet me paraphase your question:

You have exe1 that starts exe2 and then exe1 terminates.

You then want to monitor exe2 and restart exe1 if exe2 crashes.

Is that it?Yes that's correct.This should work - if exe2 exits then it will restart exe1.

If exe2 locks up then it will probably remain in the tasklist and nothing will happen. You'd have to detect the exe2 `not responding` to GET around that.

Code: [Select]@echo off
:start
"c:\folder\file1.exe"
:loop
echo waiting for 10 seconds and checking file2
timeout /t 10 /nobreak >nul
tasklist |findstr /i "^file2.exe" >nul || goto :start
goto :loopfoxdrive,

Your method works great!

Many thanks on my end.



Discussion

No Comment Found