batch-filecmdbatch-choice

batch choice command will not work


I have this question about why this choice command won't work. I've looked on this site and compared all my scripting and I just can't figure out why it won't work http://www.computerhope.com/issues/ch001674.htm

@ECHO OFF
:START
echo 1 to quit or 2 to print hello and go back to this screen
CHOICE /C:12 /N
IF ERRORLEVEL ==1 GOTO QUIT
IF ERRORLEVEL ==2 GOTO HELLO
GOTO :START
:QUIT
EXIT
:HELLO 
ECHO hello
GOTO :END
:END

Solution

  • I've made a couple of changes and removed unnecessary code.

    @ECHO OFF
    
    :START
    CLS
    ECHO=1 to quit or 2 to print hello and go back to this screen
    CHOICE /C 12 /N
    IF ERRORLEVEL 2 (CALL :HELLO & GOTO START)
    EXIT /B
    
    :HELLO 
    ECHO=hello
    TIMEOUT 2 1>NUL