mardi 27 novembre 2018

I can't understand choice error codes of batch

If I have a code like this:

@echo off
choice /C BL /M "Clear screen or list actual directory"

if errorlevel 2 goto l
if errorlevel 1 goto b

:l
tree /f
goto final

:b
cls
goto final

:final

I know this actually works, but I'm confused about one thing about the errorlevel parts. I wrote first, the same code, but like this:

if errorlevel 1 goto l
if errorlevel 2 goto b

And that way it won't work properly It will only remember the errorcode 1. If you press the second option is not working.
I'm really wondering why the order of the errors matters, if a batch its supposed to execute line by line, or am i wrong?
In a nutshell, what I want to understand is how the error codes work here

Aucun commentaire:

Enregistrer un commentaire