2

我正在尝试使用 find 命令和 errorlevel 来评估命令的结果

Setlocal EnableDelayedExpansion
...
nssm status MyService | find "SERVICE_STOPPED"
if !errorlevel! equ 0 (
   echo MyService is not running
)

由于我知道命令“nssm status MyService”返回“SERVICE_STOPPED”,我希望 find 将错误级别设置为 0。相反,它设置为 1。为什么?

4

1 回答 1

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
)
于 2016-04-12T17:16:34.973 回答