2170Views3Replies

Author Options:

Choice command works in CMD but not in a batch file Answered

I was trying to use the Choice command in Windows7 and when I tested it in CMD it worked fine, but when I try to use it in a batch nothing shows up it just stops the batch from doing anything on a blank line. So lets say my batch file was...

@echo off
echo Hi
echo Person
choice /c YN /m Will you be my friend?
if ERRORLEVEL==2 goto :end
if ERRORLEVEL==1 goto :a
echo If you see this it failed...
:a
echo YAY!
Pause>nul
:end
exit

Then I would see

Hi
Person

Then nothing after that. It would just be blinking like you have to type in something on a blank line. Any Ideas?

Discussions

0
None
KeithW129

1 day ago

I had the exact same problem. Fixed it by putting the path to the choice.exe file before the CHOICE command. Like this:

%SystemRoot%\System32\CHOICE /N /C:123 /m ".....Please choose"%1 /t 15 /d 1
IF ERRORLEVEL ==3 GOTO shutdown
IF ERRORLEVEL ==2 GOTO all
IF ERRORLEVEL ==1 GOTO essentials

Hope this helps. I don't know why it works but it did for me.

0
None
TheBatchies

9 years ago

I think you did it wrong... Let me help.

choice /cyn Will you be my friend?
if %errorlevel% equ 14 goto end
if %errorlevel% equ 25 goto a

And the /N switch makes it so you cannot see the choices, so you yourself made it so you couldn't see it! Haha, happens to me all of the time. Good question, glad if I could help.

0
None
Prof. PickleTheBatchies

Answer 6 years ago

No he didn't... He used the /M switch...

I don't know why it's not working...