3

I don't know anything about batch files and I am making one for something. I want to write a batch file which will keep running in background which itself will deal with making sure if 'java.exe' is running and if it's not then it will trigger other batch file (say 'abc.bat')

This 'abc.batch' sets some parameters and launches 'java.exe' which executes those parameters. I want this 'java.exe' to keep running and if anyone closes it, it should restart immediately by executing 'abc.bat'. Moreover, I don't want to make changes in 'abc.bat'.

If it's confusing, I would like to apologize for my writing skills and I would like you to ask for clarification.

SumeetN
  • 128
  • 1
  • 9
  • 1
    possible duplicate of [Batch program to to check if process exist](http://stackoverflow.com/questions/15449034/batch-program-to-to-check-if-process-exist) – wOxxOm Jul 28 '15 at 06:59

1 Answers1

2
@if (@X)==(@Y) @end /* JSCRIPT COMMENT **


@echo off

set process_to_check=java.exe
:repeat

cscript //E:JScript //nologo "%~f0" | find /i "%process_to_check%" >nul 2>&1 && (
    echo process %process_to_check%  is running
) || (
    echo process %process_to_check%  is not running
    call abc.bat
)
rem wait 5 minutes
ping localhost -n 1 -w 300000 >nul
exit /b

************** end of JSCRIPT COMMENT **/


var winmgmts = GetObject("winmgmts:\\\\.\\root\\cimv2");
var colProcess = winmgmts.ExecQuery("Select * from Win32_Process");
var processes =  new Enumerator(colProcess);
for (;!processes.atEnd();processes.moveNext()) {
    var process=processes.item();
    WScript.Echo( process.processID + "   " + process.Name );
}
npocmaka
  • 55,367
  • 18
  • 148
  • 187