I wrote a batch file for a legacy DOS system for games that do not run on Win32. The code works fine under XP x86 but when I run it in 98SE or in DOS I get a Syntax Error after the first prompt. The file runs through into a loop thanks to goto. How do I fix this?
Source code:
@echo off
:PROMPT
cls
echo.
echo Welcome to the Game Selection Wizard!
echo --------------------------------------
echo.
echo Please Select a Game:
echo.
echo 1. Game1
echo 2. Game2
echo 3. Return To MS-DOS
echo.
set /p GAME= Your Current Selection:
if %game%==1 goto Game1
if %game%==1. goto Game1
if %game%==2 goto Game2
if %game%==2. goto Game2
if %game%==3 goto QUIT
if %game%==3. goto QUIT
goto INVALID
:INVALID
cls
echo.
echo * * * * * * * * * * * * * * * * * * * * * * * * * * *
echo * *
echo * ERROR: *
echo * ------ *
echo * The choice you selected is wrong. Try Again! *
echo * *
echo * * * * * * * * * * * * * * * * * * * * * * * * * * *
echo.
echo Welcome to the Game Selection Wizard!
echo -------------------------------------
echo.
echo Please Select a Game:
echo.
echo 1. Game1
echo 2. Game2
echo 3. Return To MS-DOS
echo.
set /p gameerror= Your Current Selection:
if %gameerror%==1 goto Game1
if %gameerror%==1. goto Game1
if %gameerror%==2 goto Game2
if %gameerror%==2. goto Game2
if %gameerror%==3 goto QUIT
if %gameerror%==3. goto QUIT
cls
goto INVALID
:Game1
cls
call A:\GAMES\Game1.exe
goto PROMPT
:Game2
cls
call A:\GAMES\Game2.exe
goto PROMPT
:QUIT
cls
echo.
echo Are you sure you want to return to MS-DOS?
echo.
set /p quit= Confirmation:
if %quit%==y goto DIE
if %quit%==Y goto DIE
if %quit%==yes goto DIE
if %quit%==Yes goto DIE
if %quit%==YES goto DIE
if %quit%==n goto PROMPT
if %quit%==N goto PROMPT
if %quit%==no goto PROMPT
if %quit%==No goto PROMPT
if %quit%==NO goto PROMPT
goto QUITERROR
:QUITERROR
cls
echo * * * * * * * * * * * * * * * * * * * * * * * * * * *
echo * *
echo * ERROR: *
echo * ------ *
echo * The choice you selected is wrong. Try Again! *
echo * *
echo * * * * * * * * * * * * * * * * * * * * * * * * * * *
echo.
echo Are you sure you want to return to MS-DOS?
echo.
set /p quiterror= Confirmation:
if %quiterror%==y goto DIE
if %quiterror%==Y goto DIE
if %quiterror%==yes goto DIE
if %quiterror%==Yes goto DIE
if %quiterror%==YES goto DIE
if %quiterror%==n goto PROMPT
if %quiterror%==N goto PROMPT
if %quiterror%==no goto PROMPT
if %quiterror%==No goto PROMPT
if %quiterror%==NO goto PROMPT
goto QUITERROR
:DIE
cls
echo.
echo Returning to MS-DOS...
First use VER to detect the OS,by piping the output to FIND (not findstr) and looking for a 'significant string'. This only needs to be done once - so place it direcly after the @ECHO OFF
set running=NT
ver|find "1998" >nul
if not errorlevel 1 set running=DOS
"1998" is a significant string which should only appear in VER for Win98. Other valus to look for are "2222" (W98SE) and "3000" (WinME) - so simply repeat the line-pair for the strings you need to detect.
When you want to accept input, you need to use SET/P for NT or CHOICE for DOS
if %running%=NT set /p ....&goto :ntxxx :: else running DOS choice ...
where the label NTXXX is your processing for NT-input (you appear to allow "2" or "2." for example)
The CHOICE command reacts to a keystroke and sets ERRORLEVEL depending on the keystroke used. CHOICE/?
will show the syntax.
Since IF ERRORLEVEL xx
means "If errorlevel is xx OR GREATER"
then it's necessary to process the choice made in REVERSE order (last position=highest ERRORLEVEL first)
(I no longer have easy access to a pre-XP system, so all the above is from memory)
Interestingly, CHOICE re-appeared with Vista...