Automatic restart after the window under process exits

Design idea: to write a batch script running state monitoring process, if the discovery process is stopped, then automatically restart the process. Batch script (jk.bat) and processes script (hello.bat) as follows:

1、jk.bat

@echo off 
the definition of rem need to monitor the process name and path of the program, can be modified as needed 
the SET AppName = myHello.jar
 the SET AppPath = C: \ the Users \ dongbr \ Desktop \ \ the Test 
title process monitoring 
CLS 
echo. 
echo monitoring process began ... ... 
. echo 
rem define the loop 
: startjc 
   rem for the specified process from the process list 
   rem the following statement can also be written QProcess % AppName%> NUL (experience after release supplement) 
   rem QProcess | findstr / i% AppName%> NUL 
   JPS the -l | findstr / i% AppName%> NUL 
   value rem is equal to 0 indicates variable errorlevel find the process, otherwise there is no process to find 
   IF % errorlevel% == 0 ( 
         echo ^>% DATE: ~ 0 ,10 %% Time: ~ 0 , 8 % is running ...... 
    ) the else ( 
           echo ^>% DATE: ~ 0 , 10 %% Time: ~ 0 , 8 % did not find the program processes 
           echo ^>% DATE: ~ 0 , 10 % Time%: ~ 0 , . 8 % is to restart the program 
           start hello.bat 
   ) 
   REM with the ping command to implement delay operation 
   for / L %% I in ( . 1 , . 1 , 10 ) do ping -n . 1 -w 1000 168.20.0.1>nul
   goto startjc
echo on

2、hello.bat

title hello process 

SET AppName = myHello.jar
 SET AppPath = C: \ the Users \ dongbr \ Desktop \ Test \ 

 Java -jar AppPath %%% AppName% 2 > NUL && echo ^>% DATE: ~ 0 , 10 %% Time: ~ 0 , 8 % start the program successfully 
rem program completes the implementation of the exit command to exit the run window 
exit

 

Guess you like

Origin www.cnblogs.com/liuys635/p/11260158.html