Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Im trying to create a batch file to reset different portions of the TCP/IP stack. But I want to base the errorlevel of each command off of specific keywords in the output of each command, such as:
ipconfig /flushdns | find /I "failed"
Now I've got a batch created at work that runs:
ipconfig /flushdns
ipconfig /registerdns
nbtstat -RRNow when I run this batch I see the output of each command as if I ran them seperately and sometimes the /registerdns will fail if you attempt to run it more than once per two minutes. I want the :Error cooresponding to this command to be called if the text output contains the word "failed". I have tried my example above like:
ipconfig /flushdns | find /I "failed"
but when I run the batch each and every command calls the errorlevel 1 goto Error(number). Like this:@echo off
ipconfig /flushdns | find /I "failed"
errorlevel 1 goto Error1
echo Ipconfig flushed
echo offipconfig /registerdns | find /I "failed"
errorlevel 1 goto Error2
echo Ipconfig registered DNS names
echo offnbtstat -RR
errorlevel 1 goto Error3
echo Netbios cache flushed
echo offIs there anyway that I can do this? Even if it's piping the screen output to a %TEMP%\name.txt file then pulling from there...I just cannot figure it out.
Thanks!

Hi ben,
I think you're pretty close.
FIND sets errorlevel 1 if the string is NOT found. So instead of this:
ipconfig /flushdns | find /I "failed"
errorlevel 1 goto Error1I think you need:
ipconfig /flushdns | find /I "failed"
if not errorlevel 1 goto Error1Which means the string "failed" WAS FOUND.
Make sense?
BTW, you can save some typing and some clutter by eliminating all 'echo off' but the first one. Once it's off, it's off.
HTH
If at first you don't succeed, you're about average.M2

Ok cool, yeah I beileve that resolved the first half of my batch.... now last question:
towards teh bottom after the TCP/IP stack has been flushed/refreshed, I have the batch ping our router. What I wanted to do was if "TTL=" then errorlevel 1 goto Error6, like the above lines.
ping xxx.xxx.xxx.xxx | find "TTL=" >NUL
if errorlevel 1 goto Error6
echo Ping'd Successfully
echo offNow Error6 just changes the color to 04 and echos Gateway Ping Failed.
Did I use the correct syntax above for this to work? If TTL is = to NUL, then goto Error6?

"ping xxx.xxx.xxx.xxx | find "TTL=" >NUL
if errorlevel 1 goto Error6
echo Ping'd Successfully"Im a little confused. Those three lines look OK.
My confusion is with this phrase:
"f TTL is = to NUL, then goto Error6"
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

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