Bat脚本yes和回车执行方法?
我现在有下面的脚本,想实现,不管是打回车键还是打yes都可以执行关机脚本,执行也是执行其他的程序,但是总是失败:@echooff:startsetkey=set/pkey...
我现在有下面的脚本,想实现,不管是打回车键 还是 打yes都可以执行关机脚本,执行也是执行其他的程序,但是总是失败:
@echo off
:start
set key=
set/p key=are your sure? (yes,no):
if /i "%key%"=="yes" goto YY
if /i "%key%"=="y" goto YY
if /i "%key%"=="no" goto PP
if /i "%key%"=="n" goto PP
set ccc=%key%
if "%ccc%"=="" goto XX
:XX
echo ok, got it, you want the system shutdown, it will will done in 2 Secs..
shutdown /s /t 1 /f
::goto start
echo what's the mean of %key%, do you want to run it again?
pause&goto start
:YY
echo you choose the %key%, the system will shutdown in 3 Sec.
shutdown /s /t 1 /f
:pp
echo you choose the %key%, please save your file and run it again...
pause 展开
@echo off
:start
set key=
set/p key=are your sure? (yes,no):
if /i "%key%"=="yes" goto YY
if /i "%key%"=="y" goto YY
if /i "%key%"=="no" goto PP
if /i "%key%"=="n" goto PP
set ccc=%key%
if "%ccc%"=="" goto XX
:XX
echo ok, got it, you want the system shutdown, it will will done in 2 Secs..
shutdown /s /t 1 /f
::goto start
echo what's the mean of %key%, do you want to run it again?
pause&goto start
:YY
echo you choose the %key%, the system will shutdown in 3 Sec.
shutdown /s /t 1 /f
:pp
echo you choose the %key%, please save your file and run it again...
pause 展开
1个回答
展开全部
@echo off
:start
set key=
set/p key=are your sure? (yes,no):
if /i "%key%"=="yes" goto YY
if /i "%key%"=="y" goto YY
if /i "%key%"=="no" goto PP
if /i "%key%"=="n" goto PP
set ccc=%key%
if "%ccc%"=="" goto XX
:XX
echo ok, got it, you want the system shutdown, it will will done in 2 Secs..
shutdown /s /t 1 /f&exit
::goto start
echo what's the mean of %key%, do you want to run it again?
pause&goto start
:YY
echo you choose the %key%, the system will shutdown in 3 Sec.
shutdown /s /t 1 /f&exit
:pp
echo you choose the %key%, please save your file and run it again...
pause
以上代码经测试可以实现按回车或输入y都执行关机.测试环境 Winxp,Win7
追问
其实在这个脚本中如果在出现的画面中,你选择了 空格 或是 yes后,系统会执行 两条内容:
1, :XX
2, ::goto start
只不过是,我在这个条件语句下面写的是shutdown的命令,所以我个人觉得这个还是有些问题的?您觉得呢?
追答
shutdown /s /t 1 /f&exit
这是上面我修改后的语句,执行完shutdown 退出批处理,这样就不会执行下一条了.或者用goto 命令跳转
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询