如何使批处理程序停止中途

时间:2014-10-03 21:38:25

标签: batch-file

我正在制作一个我想要停止中途的批处理程序。就像我只希望它在被调用时执行其他命令一样:Command。有没有办法可以做到这一点?我不是在寻找暂停,我希望它不要播放下面的其他命令。我希望它只是停止代码的轨道。所以它在调用之前不会播放任何命令。示例如下:

@echo off
:Talk
Echo DONT DO THIS PART UNTIL CALLED
:NoName
echo Going to Talk
goto :Talk

1 个答案:

答案 0 :(得分:1)

执行此操作的常规方法是exitgoto :eofgoto也很有帮助:

使用goto :eof(表示:“转到脚本末尾”):

set /p "x=Enter a command: "
if /i "%x%"="talk" call talk
goto :eof
echo this line will never be reached
:talk
echo going to talk
goto :eof
:listen
echo listening part
goto :eof

使用exit

set /p "x=Enter a command: "
if /i "%x%"="talk" call talk
exit /b
echo this line will never be reached
:talk
echo going to talk
goto :eof

使用goto

:input
set /p "x=Enter a command: "
if /i "%x%"="talk" call talk
goto :input
echo this line will never be reached
:talk
echo going to talk
goto :eof

换句话说:用goto :eof

结束每个被调用的“子程序”