gpt4 book ai didi

batch-file - 批量ERRORLEVEL问题

转载 作者:行者123 更新时间:2023-12-03 22:28:59 24 4
gpt4 key购买 nike

我有一个文件可以检查进程是否正在运行。如果是,则循环,如果不是,则将一行回显到 txt 文件中,我的问题是,当进程未运行时,它仍然继续循环。这是我的代码

:a
Tasklist /v | findstr CMD.exe | findstr LAN
If ERRORLEVEL==1 goto :done
Goto :a

:done

Echo %USERNAME% has logged out. >>log.txt

我认为我在 ERRORLEVEL 上做错了,尽管我已经尝试过错误级别为 0-2 的 if 和 if not 语句。

最佳答案

你不能像那样用错误级别进行比较操作。试试这个:

If ERRORLEVEL 1 goto :done

if %errorlevel% == 1 goto :done

if %errorlevel% EQU 1 goto : done

当您使用 FIND 或 FINDSTR 时,您需要引号:

Tasklist /v | findstr "CMD.exe" | findstr "LAN" 

你也可以使用条件执行:

Tasklist /v | find "CMD.exe" | find "LAN" || goto :done

关于batch-file - 批量ERRORLEVEL问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16781282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com