简体   繁体   English

批处理 - “此时转到意外”

[英]Batch - “goto was unexpected at this time”

Here is the batch script I am working on:这是我正在处理的批处理脚本:

@echo off

:programBEGIN
set FILE=R3D-%input1%.txt
mode con:cols=24 lines=25
color F

set /p input1=}} INPUT: 
cls
if %input1%=="" goto ERR1
goto programLIST

:programLIST
echo Hello

:ERR1
echo Test
pause

Whenever I attempt to run the bat file and input no value, it closes with a quick prompt of "goto was unexpected at the time"每当我尝试运行 bat 文件并且不输入任何值时,它就会关闭并快速提示“当时 goto 出乎意料”

Is my formatting of the if statement correct, or is that the reason it keeps closing?我的 if 语句格式是否正确,还是它一直关闭的原因?

Because if input is not defined the script looks like this:因为如果没有定义输入,脚本看起来像这样:

if =="" goto ERR1

Which is a syntax error.这是一个语法错误。

Try like this:像这样尝试:

if "%input1%"=="" goto ERR1

Instead of using that if statement, try this instead:与其使用 if 语句,不如试试这个:

IF DEFINED input1 goto ERR1

If you must use the normal if statement, you can try this:如果你必须使用普通的 if 语句,你可以试试这个:

IF "%input1%"=="" goto ERR1

just to make sure.只是为了确保。 Other than that, I don't see where the problem would stem from.除此之外,我看不出问题出在哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM