choice.exe errorlevel not working

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

choice.exe errorlevel not working

#1 Post by Adrianvdh » 05 Oct 2013 03:29

Hi everyone.

I only noticed this problem yesterday and tried to fix it. The problem did not occur at all.

Code: Select all

choice /C 12b /N /M "Make your selection: "
if errorlevel 3 goto menu
if errorlevel 2 goto test1
if errorlevel 1 goto test2


I have no idea why it won't work any more? ANy help?

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: choice.exe errorlevel not working

#2 Post by foxidrive » 05 Oct 2013 04:17

It works here. *shrug*

Code: Select all

@ECHO OFF
choice /C 12b /N /M "Make your selection: "
if errorlevel 3 echo goto menu
if errorlevel 2 echo goto test1
if errorlevel 1 echo goto test2
%0
pause

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: choice.exe errorlevel not working

#3 Post by aGerman » 05 Oct 2013 04:31

Yes works for me too. Perhaps a problem with the context of that code snippet (that you didn't post though).

Regards
aGerman

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: choice.exe errorlevel not working

#4 Post by Adrianvdh » 05 Oct 2013 05:39

How can I fix this? CMD.exe is acting weird, all my code doesn't really work now. (Just discover 10 min ago)

Would I need to fix a reg item or something?

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: choice.exe errorlevel not working

#5 Post by aGerman » 05 Oct 2013 05:45

First try

Code: Select all

@echo off &setlocal

choice /C 12b /N /M "Make your selection: "
if errorlevel 3 goto menu
if errorlevel 2 goto test1
if errorlevel 1 goto test2


:menu
echo menu
pause
goto :eof

:test1
echo test1
pause
goto :eof

:test2
echo test2
pause
goto :eof

If you enter b it should jump to :menu, if you enter 2 it should jump to :test1 and if you enter 1 it should jump to :test2 (in order you specified it). If this doesn't work reboot your machine before you try to do any further actions :wink:

Regards
aGerman

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: choice.exe errorlevel not working

#6 Post by Adrianvdh » 05 Oct 2013 05:55

@agerman:

Returned error:

Code: Select all

Maximum setlocal recursion level reached.

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: choice.exe errorlevel not working

#7 Post by aGerman » 05 Oct 2013 05:58

:lol: The name of your batch file is choice.bat, isn't it?

N E V E R call a batch file the same as one of the commands it contains!

Regards
aGerman

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: choice.exe errorlevel not working

#8 Post by Adrianvdh » 05 Oct 2013 06:12

Oh ok :)

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: choice.exe errorlevel not working

#9 Post by Adrianvdh » 05 Oct 2013 06:29

Ok it works now :)

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: choice.exe errorlevel not working

#10 Post by Adrianvdh » 05 Oct 2013 06:35

Adrianvdh wrote:THANKS!!!, Using the "!" instead worked :), Thanks

P.S. Would you recommend I do this for ALL errorlevel arguments? (Use "!" instead)


viewtopic.php?f=3&t=4961

Post Reply