批处理文件,用于检查另一个批处理文件进程

时间:2016-06-24 00:06:43

标签: windows batch-file cmd tasklist

所以谷歌根本没有帮助我,我需要再次问这里。 我使用这种方法检查我的服务器是否在2个批处理文件中运行。

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
)

一个启动,一个停止服务器。 嗯这很好用但是当涉及到批处理文件时它对我不起作用...... 我有一台服务器在phyton上运行,所以通过批处理文件启动它。 我的问题是,有没有办法以某种方式得到批处理文件进程状态并停止它像exe工作? 我希望我解释得足够好。 Thx提前! :)

2 个答案:

答案 0 :(得分:0)

您可以使用以下批处理文件进行尝试:

@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

答案 1 :(得分:0)

Omg我找到了解决方案,这是一只野兽......

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

但是starmnge是什么让我无法让输出变得笨拙...... 当我尝试将其静音时,它总是给出错误级别1。

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

这有什么不对吗? ^