1

My apologizes if this question is asked before but i couldn't find a correct match with my situation.

I have some batch files, they are always running because of the java program running inside them. However, sometimes they crash and since i am not monitoring them, some amount of time passes till i restart them.

I want to ask that is there a way to monitor those batch files, or how can i restart those batch files even if they crash. I am running those files on Windows XP.

Thanks

emrahsamdan
  • 203
  • 4
  • 13

3 Answers3

1

Have you tried this?
http://www.ghacks.net/2009/08/31/monitor-and-restart-crashed-windows-processes/

Alin Stoian
  • 1,122
  • 1
  • 12
  • 24
  • it seems good to me, but i have like 20 barch files to run. This program seems to be configured for only one process. Do you know a way to adjust this program to monitor multiple processes at once. – emrahsamdan Feb 17 '12 at 12:13
1

You can start a batch file from another batch file in a loop. When it is started, the loop waits. Once it crashes - the loop starts it over.

weekens
  • 8,064
  • 6
  • 45
  • 62
  • hi, i have also read this from somehere else, but i am unfamiliar to batch writing. Could you please give the example of this batch code. I mean loop example. in case the name of my .bat is emrah.bat. – emrahsamdan Feb 17 '12 at 12:21
  • Just google it out. There are topics on SO, for example [this one](http://stackoverflow.com/questions/1788473/while-loop-in-batch) – weekens Feb 18 '12 at 08:39
0

Replace each call to java with a goto loop that calls java via cmd.exe. Conditionally loop back only if the java program exited with an error.

.
.
:javaLoop
cmd /c java yourJavaProg || goto :javaLoop
.
.

You might want to guard against an endless rapid loop in the case of a complete failure by adding a counter to limit the number of times it restarts. Another possibility is to note the time and only restart if a minimum amount of time has elapsed since the last restart. Or perhaps a combination of both.

EDIT - On second thought, you may not need the CMD /C. It may work fine just by invoking java directly and conditionally looping upon error.

dbenham
  • 127,446
  • 28
  • 251
  • 390