Use Windows command line tools tasklist and findstr, start combined with scheduled tasks

Although Windows is good at UI. However, the real POWERFUL tool is still on the command line.

Today, I will introduce a solution to monitor whether a process is working normally by using the Windows command line tools tasklist and findstr, start.

tasklist : List all processes currently executed by the system;

findtr : Use regular expressions to search for specified content in strings or text files;

start : start a target with a mode defined by some parameters

At the same time, the channel | in the command line is also used, which is a supper channel.

The scheme is as follows:

Assume that there is a service process called python, and this service is allowed to be temporarily unavailable, assuming 5 minutes;

This python will automatically exit when an exception occurs;

In order to ensure that this process can continue to provide services, we create a BAT batch file, add it to the system's  scheduled tasks  , and set the execution cycle to 3 minutes;

In the BAT file, write the following content:

tasklist | findstr /i python.exe

IF ERRORLEVEL 1 start /b python.exe

tasklist | findstr /i python.exe  is in the system process list, find python.exe

IF ERRORLEVEL 1 start /b python.exe  If the above lookup does not match, start python.exe

Guess you like

Origin blog.csdn.net/leonnew/article/details/128289604