Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Does anyone know how to do any of the following.
How to test if a modem is already in use and then exit the batch program if it is.
or
Ping an IP address, if there is no response then exit the batch program.
If anyone can help you will be my friend for life. promise........

Number two is relatively simple. Use ping with whatever parameters you wish (ie. only one ping versus the usual four and of course the DNS name or IP address), then check the errorlevel to see if it was successful. Example:
ping someone
echo %errorlevel%Now, try one you know will work and one you know will fail and see what is echo'ed each time. With any luck, they'll be two different numbers. They were on the NT machine I wrote this for for someone some time ago. However I think they were the same for them on a 9x machine. If they *are* different, then replace the echo with an if check for the bad value (always check for the highest possible value first with Batch if's) and a goto. Example:
ping someaddress
if errorlevel=1 goto error
echo we were successful!
goto end:error
echo we failed!:end
If they are the same, you could probably do it with redirection and find. Example:
ping someone > ping.txt
find "timed out" ping.txtThe above is essentially pseudocode though as I ceased Batch programming right as I began to learn find.com.

Ok, I tried to get the error level and it was the same value for a good and bad ping. The value was always 'zero'. This may mean that I can't do it on NT.
Do you have any other methods that I could try.
...........

I tried your 'find' solution and then tested the error level. This works perfectly.
Many thanks for your help on this one.
Regards
Sandy - Babe abroad

Oh good. The errorlevel with ping should have worked for NT. I was doing it on my NT Server machine. Wonder if I typed something wrong... Glad to hear you got it to work nonetheless. :)

![]() |
product key
|
Batch files at shutdown
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |