What is wrong with this Batch (.bat) file?

I wasn't aware there was "0" values in an IP address. I thought they went from 1 to 255.
If not I learned something new.
 
I meant the errorlevel not ip address.



If you put in an errorlevel they are listed 0 and up.
0 usually isn't listed because it will just default. But if you only use one errorlevel or one given answer then it will default to 0

If you wanted errorlevel1,2,3 or what ever, then you would need to specify what the error would be. Being that we are not using a specific answers (Different ip addresses) dos, ms-dos and command prompt will automatically override your errorlevel and use errorlevel 0. So here we specify what the errorlevel 0 is going to do. In our case, it's the goto command.
 
Last edited:
I'm not sure we are talking about the same thing here.

errorlevel in a batch file doesn't really care if you put in an ip address or not. If the command you are running in the batch doesn't complete correctly it will try to continue, in this case, it will continue to errorlevel 0. In the case of the OP he/she was using errorlevel 2 which would make them specify a specific answer. Since this couldn't be achieved the batch defaulted to errorlevel0 resulting in a loop.

BTW, I run XP and Windows 7
 
Does error level mean a return code?

I.E
@echo off
:start
cls
color f4
choice /c "1-Exit 2-Shutdown"
if errorlevel 2==goto shutdown
if errorlevel 1==goto exit
:shutdown
shutdown -s -f -t 10 -c Shutting down in ten secs
:exit
exit
:end
 
Your new code is close. But may work.

In windows 7. I'm not sure when version of Choice you are using.
but in windows 7 your code would be

choice /C:12 /N /M "1-Exit 2-Shutdown"
if errorlevel 2==goto shutdown
if errorlevel 1==goto exit

Your Shutdown command is broke as well.


But yes, thats the right idea there. Now you can add as many as you like.
For example. you could add a new goto area called reboot and just adjust your shutdown command to reboot the pc instead of shutdown. So then you could have 3 errorlevels.
 
This one pings ok, but when it go to the errorlevels it just exits, whats up with this .bat?

CODE:

@echo off
:start
cls
color f4
set /p name=Enter Name
echo ****************************
echo Welcome %name%
echo ****************************
pause
cls
echo Enter IP Address Or Domain Name
pause
cls
set /p ip=Enter IP Address
ping %ip%
echo COMPLETE!!!
pause
cls
choice /c:12 "1-Start Over 2-Exit"
if errorlevel 2==goto stop
if errorlevel 1==goto begin
:stop
exit
:begin
goto start
:end
 
Oh So close!!

You need the /M switch in your Choice command before your text display.

@echo off
:start
cls
color f4
set /p name=Enter Name
echo ****************************
echo Welcome %name%
echo ****************************
pause
cls
echo Enter IP Address Or Domain Name
pause
cls
set /p ip=Enter IP Address
ping %ip%
echo COMPLETE!!!
pause
cls
choice /c:12 /M "1-Start Over 2-Exit"
if errorlevel 2==goto stop
if errorlevel 1==goto begin
:stop
exit
:begin
goto start
:end

Just to clean up the code a bit. In your errorlevel1. Change the goto to start.
Then you can remove the :begin and goto command.
 
Last edited:
No problems.
when my stepfather gave me his computer when i was younger (Amstrad PC 8088)

There wasn't anything much you could do.
So a lot of times I just played around with autoexec and batch files.
 
Back
Top Bottom