我的 goto 重定向不起作用,但可以使用 echo [英] my goto redirect is not working but works with echo

查看:26
本文介绍了我的 goto 重定向不起作用,但可以使用 echo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@echo off  
:start1  
set /p input=action :   
for /f "tokens=1-2 delims= " %%a in ("%input%") do (  
goto :%%~a_%%~b >nul 2>&1 || goto start1
)    

如果我输入| | echo your input is not Recognized",它可以工作,但goto start1"会使脚本崩溃

if I put "| | echo your input is not recognized" it works, but the "goto start1" crashes the script

:explore_room   
@echo room explored  
goto start1  
pause  
:examine_door  
@echo door examined  
pause  
:examine_wall  
@echo wall examined  
pause  

推荐答案

@echo off  
:start1  
set /p input=action :   
call :%input: =_% 2>nul
if errorlevel 1 echo your input is not recognized
goto start1


:explore_room   
@echo room explored  
pause  
exit /B 0

:examine_door  
echo door examined  
pause  
exit /B 0

:examine_wall  
echo wall examined  
pause 
exit /B 0

例子:

action :   examine door
door examined
Presione una tecla para continuar . . .
action :   explore hall
your input is not recognized
action :   explore room
room explored
Presione una tecla para continuar . . .
¿Desea terminar el trabajo por lotes (S/N)? s

这篇关于我的 goto 重定向不起作用,但可以使用 echo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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