中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-01 15:50
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 请帮我看看这个脚本错在哪里,谢谢 查看 963 回复 2
楼 主 请帮我看看这个脚本错在哪里,谢谢 发表于 2006-06-04 08:00 ·  中国 江苏 苏州 教育网
初级用户
积分 20
发帖 4
注册 2006-06-03 10:58
20年会员
UID 56478
状态 离线
刚开始学习批处理
这个简单的脚本为什么每次都跳到First.
懂得的朋友帮忙解释一下,谢谢了
还有,能介绍一下choice返回值的方式吗


@echo off
:start
choice /C:FSTO /M "First,Second,Third,Out"
if errorlevel 1 goto First
if errorlevel 2 goto Second
if errorlevel 3 goto Third
if errorlevel 4 goto end
:First
echo This is the first line.
goto start
:Second
echo This is the Second line.
goto start
:Third
echo This is the Third line.
goto start
:end
echo bye!
2 发表于 2006-06-04 10:49 ·  中国 四川 成都 联通
铂金会员
★★★★
积分 7,493
发帖 2,672
注册 2005-09-02 00:00
20年会员
UID 42173
性别 男
状态 离线
ErrorLevel x 是指 大于 或等于 x 的情况!所以要倒着写!

if errorlevel 4 goto end
if errorlevel 3 goto Third
if errorlevel 2 goto Second
if errorlevel 1 goto First

初学者编ErrorLevel最易范的错误 ^_^

chioce的用法自己看帮助!

[ Last edited by electronixtar on 2006-6-4 at 10:51 ]

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
3 发表于 2006-06-04 10:50 ·  中国 广东 广州 海珠区 电信
荣誉版主
★★★
积分 718
发帖 313
注册 2005-09-26 00:00
20年会员
UID 42844
性别 男
状态 离线
RE ziver :
A:使用本论坛的搜索功能比你请教,将节省你很多等候的时间,并你能见到更多的例子,了解得将更多.
B:错误码应从最高值一直往下判断.
if errorlevel 4 goto end
if errorlevel 3 goto Third
if errorlevel 2 goto Second
if errorlevel 1 goto First

C:如果不用错误码判断,可以从用户输入的字符来判断. 见链接{1}
D:相关链接:
{1}http://www.cn-dos.net/forum/viewthread.php?tid=15763&fpage=1&highlight=choice
{2}http://www.cn-dos.net/forum/viewthread.php?tid=6287&fpage=1&highlight=choice
{3}http://www.cn-dos.net/forum/viewthread.php?tid=19414&fpage=1&highlight=choice
{4}http://www.cn-dos.net/forum/viewthread.php?tid=5675&fpage=1&highlight=choice

***************
请尽快修改贴子主题.不然willsort版主要来罚你的积分了!哈哈
建议主题:关于choice命令与errorlevel 的问题
***************

[ Last edited by 220110 on 2006-6-4 at 15:24 ]
论坛跳转: