与ERRORLEVEL批处理命令选择不工作 [英] batch choice command with errorlevel isn't working

查看:179
本文介绍了与ERRORLEVEL批处理命令选择不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我越来越迷茫与选择命令。
这里是我的code:

I am getting confused with the choice command. here is my code:

@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

问题是每次我肯定的时间。我想通了,如果我用这个:

the problem is every time I get yes. I figured out if I used this:

set x=%errorlevel%

,然后用

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

和脚本workes罚款。为什么是这样?我想我记得读一些有关检查ERRORLEVEL如有虚假实际上可以设置一个新的错误级别,或者类似的东西。有一点帮助?

and the script workes fine. Why is this? I think I remember reading something about checking errorlevel could actually set a new errorlevel if false, or something like that. A little help?

推荐答案

将构建如果错误级别ñ检查ERRORLEVEL的是至少n。所以,如果错误级别为4,则测试如果ERRORLEVEL 1 如果错误级别4 ,所有的人,返回true。

The construct if errorlevel n checks if the errorlevel is at least n. So if errorlevel is 4, then the tests if errorlevel 1 to if errorlevel 4, all of them, return true.

做测试的方法是从更高ERRORLEVEL去降低ERRORLEVEL

The way to do the test is go from higher errorlevel to lower errorlevel

if errorlevel 2 goto no
if errorlevel 1 goto yes

这篇关于与ERRORLEVEL批处理命令选择不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆