set /p empty answer crash

it’s not the set /pthat crashes, but:

if %input%==new 

if %input% is empty, this is parsed as:

if ==new 

obviously a syntax error. To avoid this, use:

if "%input%"=="new"

An empty input will then be parsed as:

if ""=="new"

which works fine.

The same applies when the variable contains only spaces and/or tabs:

if == new (syntax error) versus if " " == "new" (running fine)

Complete code like this:

:Menu
set input=
set /p input=What do you want to do? 
if "%input%"=="new" goto INTRO
if "%input%"=="instructions" goto INSTRUCTIONS
if "%input%"=="quit" goto EXIT
REM for any other (invalid) input:
goto :Menu

Leave a Comment