问题描述
所以基本上我是在批量创建终端时使用的,这个奇怪的错误会弹出一秒钟,然后窗口关闭:此时,Goto出乎意料"我不知道是怎么回事.这是我的代码:
So basically I was working on my Terminal I am creating in batch and this strange error pops up for a second and then the window closes:"Goto was unexpected at this time"I have no idea what's going on. Here's my code:
@ECHO off
set codename=Nature
echo Windows Bat Terminal
echo Codename "%codename%"
:terminal
set /p terminalcommand=Command:
if %terminalcommand%==help goto help
if %terminalcommand%==clr goto clear
if %terminalcommand%==exit goto exit
if %terminalcommand%==color goto color
if %terminalcommand%==time goto timedate
echo.
echo Bad command!
:terminal1
goto terminal`
要重新创建,只需在CMD中运行它即可.
To recreate simply run this in CMD.
推荐答案
您尚未告诉我们您为生成此行为所做的输入.标准的解决方法是在if比较(如果/i%terminalcommand%" =="time" goto ...(/i使比较不区分大小写))之间加引号,因为如果您只是按Enter,则命令解析为如果== time goto ...",则cmd将在goto处看到期望==这样的比较运算符的位置,从而得到响应.如果您从命令提示符处运行该批处理,则该窗口不会关闭,您将能够更好地查看这些消息
You haven't told us what entry you made to generate this behaviour. The standard cure is to quote each side if the if comparison (if /i "%terminalcommand%"=="time" goto ... (the /i make the comparison case-insensitive)) because if you simply press enter then the command is resolved to "if ==time goto ..." and cmd will see goto where it expects a comparison operator like ==, hence the response. If you run this batch from the command prompt, the window won't close and you'll be able to see these messages better
这篇关于此时,后藤出乎意料[BATCH]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!