gpt4 book ai didi

batch-file - 错误级别的批处理选择命令不起作用

转载 作者:行者123 更新时间:2023-12-03 11:15:57 25 4
gpt4 key购买 nike

我对选择命令感到困惑。这是我的代码:

@echo off
:start
cls
echo yes or no?
Choice/c yn
if errorlevel 1 goto yes
if errorlevel 2 goto no
:yes
echo you pressed yes
pause
goto start
:no
echo you pressed no
pause
goto start

问题是每次我得到肯定。我想出了如果我用这个:

set x=%errorlevel%

然后使用

if %x%==1 goto yes
if %x%==2 goto no

脚本运行良好。为什么是这样?我想我记得读过一些关于检查错误级别实际上可以设置一个新的错误级别如果为假,或类似的东西。有一点帮助吗?

最佳答案

构造 if errorlevel n 检查错误级别是否至少为 n。因此,如果 errorlevel 为 4,则测试 if errorlevel 1if errorlevel 4,所有这些都返回 true。

测试的方法是从高错误级别到低错误级别

if errorlevel 2 goto no
if errorlevel 1 goto yes

关于batch-file - 错误级别的批处理选择命令不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21534486/

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