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

WYSIWUG

In Runtime
Messages
381
Location
New Zelaland
Hi Internet Land,


Can someone help me with this?

After I enter 192.168.0.1 and press enter, the batch file will go back to start, can someone point out what is wrong, and correct it? (Ignore all echo's)

Thanks


@echo off
color f4
cls
:start
echo ******************************************************************************************************************************
echo Welcome To Auto Ping, Please enter the IP address or Domain Name on next screen, please use Ctrl+C to stop pinging at any time
echo ******************************************************************************************************************************
pause
cls
set /p address=Enter IP address or Domain Name
ping %address% -t -l 1 -w 10000
pause
exit
:end
 
Works OK for me.

Why do you have :start and :end anyway? They aren't needed.


So if I wanted to put a if errorlevel in somewere,

I.E. if errorlevel 2==goto start (or end)

---------- Post added at 08:44 AM ---------- Previous post was at 08:42 AM ----------

It's still going back to the start after I enter 192.168.0.1 and hit Enter, it wont even start a ping request.
 
As I said, it works fine for me, not sure why it goes back to :start for you.

When you want to add the errorlevel checking, you will probably want the :start label to be immediately after @echo off and the :end label to be prior to exit.
 
Oh man... It still wont work, it still jumps back to the start, I'll take out the switches in the ping command and see what happens, stand by...
 
Tell us more about the environment. What kind of computer are you running on and do you have admin rights?


Like Strollin the bat works just fine for me. There is nothing wrong with it.
 
I did a bit of tinkering with your batch coding... (old batch file tinkerer here.).

Code:
Echo off
COLOR f4
CLS


ECHO ************************************************** ************************************************** **************************
ECHO Welcome To Auto Ping, Please enter the IP address or Domain Name on next screen, please use Ctrl+C to stop pinging at any time
ECHO ************************************************** ************************************************** **************************
PAUSE
CLS


ECHO Enter your IP address or Domain Name to ping.
:Input
SET /P address=
ping %address% -t -l 1 -w 10000
IF errorlevel 0 goto RedoIP

GOTO End

:RedoIP
ECHO There was an error in your IP or Domain address
PAUSE
GOTO IPinput

:IPinput
CLS
ECHO Please re-enter your Ip address or Domain Name to ping.
GOTO Input

:End
exit

I've tested and it works for me..
 
The above code worked, thanks. I still am stumped as to why my first attempt was rubbish, I showed the code a batch programmer, he also said there was nothing wrong with my code, he also said it might be a setting in the Active Directory Group
Policy preventing the file from being able to execute. I dont have the rights on school computers to get into MMC at all.
 
I think when you were putting in your errorlevel 2 was causing your loop.

added a few "goto"s and put in the errorlevel 0 to shoot it to the gotos.
 
Back
Top Bottom