简体   繁体   中英

Batch File which checks for another Batch File process

so google didn't help me at all i need to ask here again. I use this kind of method to check if my servers are running in 2 batch files.

tasklist /FI "IMAGENAME eq server_64.exe" 2> nul | find "server_64.exe" > nul
IF ERRORLEVEL == 1 (
echo Server is not running
echo.
) else (
echo Stopping Server ...
echo.
taskkill /F /IM server_64.exe > nul 2>&1
)

One to start and one to stop the servers. Well this works great but when it comes to batch files it wont work for me... I have one server which runs on phyton so start it via batch file. My question is, is there a way to get somehow the batch file process status and stop it like it works for exe? I hope i explained it good enough. Thx in advance! :)

You can try it with a batch file like this :

@echo off 
set "Process=server_64.exe"
Title Checking for status of this process ===^> "%Process%"
tasklist /nh /fi "imagename eq %Process%" 2>nul |find /i "%Process%" >nul
IF '%ERRORLEVEL%' EQU '1' (
    Color 0B
    echo.
    echo "%Process%" is not running
) else (
    Color 0C
    echo.
    echo Stopping "%Process%" ...
    taskkill /F /IM "%Process%" > nul 2>&1
)
pause

Omg i found the solution, this was a beast...

tasklist /fi "imagename eq cmd.exe" /v /fo table /nh | find /i "Broker" 2>nul

but what is starmnge is that i cant get the output to be silnce... when i try to mute it it gives me always error level 1.

tasklist /fi "imagename eq cmd.exe" /v /fo table /nh 2>nul | find /i "Broker" 2>nul

so whats wrong with this? ^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM