Board logo

标题: choice选择后执行顺序总是不对?附批处理全文 [打印本页]

作者: piepie     时间: 2007-1-16 23:41    标题: choice选择后执行顺序总是不对?附批处理全文

做了一个启动的批处理,希望能根据选择从相应盘中恢复克隆文件,但是不管选择1还是2还是3,总是执行第一个,也就是下文的:_restore4,请指教!

-------------------------
@echo off

rem 这里设置环境和默认加载项
rem 加载smartdrive
%RAMDRIVE%
sm

rem 菜单部分
rem 显示菜单,choice后判断选择的序号来作处理。errorlevel 0是break后的处理

:_top
cls
%RAMDRIVE%
lh TW /np /n3 >nul

echo.               数 据 恢 复
echo.
echo 1  使用 第1硬盘 第2分区(D盘) 根目录下的SYSBAK.GHO 恢复,覆盖C盘
echo 2  使用 第1硬盘 第3分区(E盘)根目录下的SYSBAK.GHO 恢复,覆盖C盘
echo 3  使用 第1硬盘 第4分区(F盘) 根目录下的SYSBAK.GHO 恢复,覆盖C盘
echo.
echo H  帮 助
echo Q  退 出 菜 单 (使用menu再次显示本菜单)
echo ---------------------------------------------------------
choice "请输入功能代码(123HQ): ",123HQ

if errorlevel 5 goto _exit
if errorlevel 4 goto _help

if errorlevel 3 goto _restore4
if errorlevel 2 goto _restore3
if errorlevel 1 goto _restore2
if errorlevel 0 goto _close


:_cdrom
rem 加载光驱,完成后暂停查看结果
cls
rem TW /Q>nul
lh device cd.sys /D:SHSU-CDH
lh mscdex /D:SHSU-CDH
pause
goto _top

:_mouse
rem 加载鼠标
cls
rem TW /Q>nul
lh mouse /w
lh MOUSCLIP /m
pause
goto _top

:_help
rem 帮助
cls
lh read.com menu2.txt
goto _top


rem --------------------------------------

:_restore4
rem 从4恢复,出错提示并返回菜单。正确重新启动
cls
echo 以下操作将从F盘的备份恢复,删除C盘所有数据!!!
echo 恢复完成后,将重新启动。
choice "是否开始恢复操作? 按Y确定,按N取消操作: ",yn
if errorlevel 2 goto _top
GHOST -clone,mode=pload,src=1:4\sysbak.GHO:1,dst=1:1 -sure -rb
if errorlevel 1 goto _reserror
goto _REstart


:_restore3
rem 从3恢复,出错提示并返回菜单。正确重新启动
cls
echo 以下操作将从E盘的备份恢复,删除C盘所有数据!!!
echo 恢复完成后,将重新启动。
choice "是否开始恢复操作? 按Y确定,按N取消操作: ",yn
if errorlevel 2 goto _top
GHOST -clone,mode=pload,src=1:3\sysbak.GHO:1,dst=1:1 -sure -rb
if errorlevel 1 goto _reserror
goto _REstart

:_restore2
rem 从2恢复,出错提示并返回菜单。正确重新启动
cls
echo 以下操作将从D盘的备份恢复,删除C盘所有数据!!!
echo 恢复完成后,将重新启动。
choice "是否开始恢复操作? 按Y确定,按N取消操作: ",yn
if errorlevel 2 goto _top
GHOST -clone,mode=pload,src=1:2\sysbak.GHO:1,dst=1:1 -sure -rb
if errorlevel 1 goto _reserror
goto _REstart


rem --------------------------------------
:_ghost
ghost
goto _TOP

:close
rem 关闭的处理,退出所有加载项
TW /np /n3 >nul
echo.
echo.
echo.
echo.
echo.         在命令行下,输入 menu 返回此菜单!!!
echo.
echo  按任意键继续..........
pause      

tw /q >nul
MOUSCLIP /u
mouse /u
cls
goto ext


:_bakerror
rem 备份出错提示,返回菜单
call w.bat box @menu.bat:scx_bf
:scx_bf
*****************************************************************

        发生错误,可能是硬盘没有找到。请按【确定】返回菜单。

*****************************************************************
                                                [ 确定(&O) ]
::
goto _top

:_reserror
rem 恢复出错提示,返回菜单
call w.bat box @menu.bat:scx_hf
:scx_hf
*****************************************************************

        发生错误,可能文件不存在。请按【确定】返回菜单。

*****************************************************************
                                                [ 确定(&O) ]
::
goto _top

:_REstart
rem 重新启动计算机
restart.BAT

:_exit
作者: tao0610     时间: 2007-1-17 07:51
choice要加参数
choice /m "请输入功能代码(123HQ): " /c 123HQ

作者: piepie     时间: 2007-1-19 22:17
这个可能是choice版本的命令不同。我在dos下运行,语法如下:

CHOICE - Waits for the user to choose one of a set of choices.

Syntax: CHOICE [/T:hh:mm:ss] "prompt"[,keylist]

Default timeout = 1 minute.  Keylist is case-insensitive.
If keylist is omitted, any keystroke will terminate the delay.
Returns errorlevel code = position of keystroke within list, 0 = timed out.

这个问题看来还是没有解决。
作者: piepie     时间: 2007-1-20 05:18
下了一个msdos7.1用的choice,语法如下。修改后问题依旧。

CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn] [text]

/C[:]choices Specifies allowable keys. Default is YN
/N           Do not display choices and ? at end of prompt string.
/S           Treat choice keys as case sensitive.
/T[:]c,nn    Default choice to c after nn seconds
text         Prompt string to display

ERRORLEVEL is set to offset of key user presses in choices.
作者: chenall     时间: 2007-1-20 11:21
应该是标签太长了.
在DOS下标签尽量不要超过8个字符.
将_restore4之类的标签前面的_去掉就刚好8个字符,再试试