Windows批处理:查找命令和错误级别

Windows批处理:查找命令和错误级别,windows,batch-file,cmd,nssm,Windows,Batch File,Cmd,Nssm,我试图使用find命令和errorlevel来评估命令的结果 Setlocal EnableDelayedExpansion ... nssm status MyService | find "SERVICE_STOPPED" if !errorlevel! equ 0 ( echo MyService is not running ) 因为我知道命令“nssmstatus MyService”返回“SERVICE_STOPPED”,所以我希望find将errorlevel设置为0。 相

我试图使用find命令和errorlevel来评估命令的结果

Setlocal EnableDelayedExpansion
...
nssm status MyService | find "SERVICE_STOPPED"
if !errorlevel! equ 0 (
   echo MyService is not running
)
因为我知道命令“nssmstatus MyService”返回“SERVICE_STOPPED”,所以我希望find将errorlevel设置为0。 相反,它被设置为1。
为什么?

删除的答案显示了
nssm
输出的编码(我没有,所以无法验证)。每个字母都用两个字节编码(第二个字节为
0x00
)。因此,这种(公认丑陋的)解决方法应该奏效:

nssm status MyService | findstr "S.E.R.V.I.C.E._.S.T.O.P.P.E.D"
if !errorlevel! equ 0 (
    echo MyService is not running
)

您是否尝试过nssm状态MyService |更多|查找“服务已停止”?我认为
more
有一些转换功能。。。