Yesterday, I have downloaded the choice.com
command from this FTP link to use it on Windows XP. From command line it works correctly, as you can see in this example:
C:\DOCUME~1\Rodolfo>choice /c:12345 "Choose the output:"
Choose the output:[1,2,3,4,5]? 5
C:\DOCUME~1\Rodolfo>echo %ERRORLEVEL%
5
I try to use it also into a batch file but, although the syntax seems to be correct, it creates an infinite loop, as shown in the following quotation:
Press any key to continue...
Press any key to continue...
Press any key to continue..
Here are the instructions inside the Batch file:
@echo off
pause
choice /c:12345 "Choose your output:"
if %ERRORLEVEL% EQU 1 echo You have chosen 1
if %ERRORLEVEL% EQU 2 echo You have chosen 2
if %ERRORLEVEL% EQU 3 echo You have chosen 3
if %ERRORLEVEL% EQU 4 echo You have chosen 4
if %ERRORLEVEL% EQU 5 echo You have chosen 5
pause
So, why does this command seem to not work correctly in Batch files although it works fine from command line?
Don't call your batch file
choice
as it executes itself in a loop.