【问题标题】:IF VAR batch file not working如果 VAR 批处理文件不起作用
【发布时间】:2013-11-07 11:03:30
【问题描述】:

谁能告诉我为什么这不起作用。当我输入 ether 1 或 2 时,我希望它显示为 goto,但当我输入数字时它会一直显示为 ECHO ERROR,任何人都可以帮忙:-)。

ECHO OFF

ECHO Loading...

SET option=0

SET /P option=Choose a number and press enter. :

ECHO %option%

if "%option" == "1" GOTO one

if "%option" == "2" GOTO two

GOTO EXIT

:one

ECHO hello

GOTO EXIT

:two

ECHO hi

GOTO EXIT






:EXIT
ECHO EXIT
Taskkill /f /im program.bat 2>%USERPROFILE%\temp.txt



ECHO ERROR

pause

【问题讨论】:

    标签: windows file batch-file cmd


    【解决方案1】:

    这一行

    if "%option" == "1" GOTO one
    

    应改为:

    if "%option%" == "1" GOTO one
    

    第二种情况同上。

    ERROR 将始终显示,因为它会从 EXIT 掉出,如果您想要 ERROR 的案例;

    :EXIT
    ECHO EXIT
    GOTO EOF
    
    ECHO ERROR
    
    :EOF
    PAUSE
    

    【讨论】:

      【解决方案2】:
      if "%option" == "1" GOTO one
      
      if "%option" == "2" GOTO two
      

      这里的结束百分号在哪里?

      【讨论】:

        猜你喜欢
        • 2019-02-14
        • 1970-01-01
        • 2015-03-07
        • 1970-01-01
        • 2016-01-09
        • 2011-06-07
        • 2023-03-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多