If errorlevel goto label ??

April 9, 2009 at 16:55:42
Specs: Windows Vista
I have a question, What is wrong with this script?

echo off
choice /c yn
if errorlevel 1 goto :label1
if errorlevel 2 goto :label2
goto :start
echo you chose yes.
pause >nul
echo you chose no.
pause >nul

I cant get it to work! Please tell me what im doing
wrong. And the easiest way to fix it.

Thanks for any reply

See More: If errorlevel goto label ??

Report •

April 9, 2009 at 18:45:19
"if errorlevel x command" means if the errorlevel is greater than or equal to x do command, so start from the highest number and work your way down:

if errorlevel 2 goto :label2
if errorlevel 1 goto :label1

Your choice command also doesn't look quite right, "choice /c:yn" vs "choice /c yn".

Report •

April 9, 2009 at 18:53:55
Ah, Thanks! Suppose it makes sense :D

Report •

April 9, 2009 at 23:11:44
You can save some typing and clutter.

:: goto choice

@echo off & setLocal EnableDelayedExpansion

goto :!errorlevel!

echo here's 1 & goto :eof

echo here's 2 & goto :eof

If at first you don't succeed, you're about average.


Report •

Related Solutions

Ask Question