Im writing a script to ping WAPs and Switches within a school and everything on it is running great aside from it will not pipe no responses into a .txt because I have added


This is basically my script aside from mutlitple lines for all the IP's

@echo off
del Test.txt
set /p var1=How many times would you like to test the connection for each device?
echo Testing WAP Connections, Please Wait...
ping -n %var1% | FIND "TTL=" > Test.txt

when I run the script with the "FIND" part of the script i get this output

Reply from bytes=32 time<1ms TTL=255

but if i dont get a reply from whatever i am pinging, it wont make a record of it in the .txt file. Is there any way I can get it to record a failed ping without having to get rid of: " | FIND "TTL=""?

  • The line, del Test.txt is not needed. The > in the ping line will overwrite the file at a better time (that will let your users press ctrl+C during the input and leave the old test data). – krowe Aug 11 '14 at 7:57

Is there any way I can get it to record a failed ping without having to get rid of: " | FIND "TTL=""?

No, at least not using Microsoft's stock find command.

Here's some documentation for find which on the client side applies to Windows Vista and Windows 8 that states, in part:

If you do not use /i, find searches for exactly what you specify for String.

Since you can only specify one String to search for, there is no direct way to do what you are trying to do.

You can, however, do it in a slightly roundabout way: redirect the output of ping to a temporary file, and run find twice on that file:

ping -n %var1% > Test.tmp
FIND "TTL=" Test.tmp > Test.txt
FIND "Request timed out." Test.tmp >> Test.txt

Or you can use a tool that supports searching for multiple distinct strings, such as GNU grep (which is available for Win32). An alternative approach pointed out in a comment by and31415 is to use findstr instead, which is available in Windows 2000 and newer:

ping -n %var1% | findstr /c:"TTL=" /c:"Request timed out."

Obviously, since both of these operate by looking at the native language output of ping they will have problems with non-English locales.

It's worth remembering that find originated in DOS 2.0. That was the same version of DOS that introduced directories, and hard disk support (DOS 1.x only supported using floppy disks for persistent storage, and lacked the concept of directories). Since backwards compatibility is something that Microsoft still takes quite seriously, they cannot easily change how find treats the String parameter, and back in the DOS 2.0 days, both memory and processing speed were at huge premiums. It appears that the find in DOS 2.x didn't even support case insensitive searching (added later with the /I switch). It is an arcane utility, really, surviving much because it cannot trivially be replaced with something different.

  • You basically just explained why the common GNU tools should be included on every Windows installation everywhere BTW. Start adding it to your ghost images and you'll be glad you did. – krowe Aug 11 '14 at 8:07
  • 1
    If the OP is using Windows 2000 or later, then findstr should be available. That means you can search multiple strings, for example: ping | findstr /c:"TTL=" /c:"timed out" That wouldn't work on non-English locales, but findstr doesn't support Unicode anyway. – and31415 Aug 11 '14 at 9:22
  • @user3582046 See my update just now based on and31415's comment. – a CVn Aug 11 '14 at 11:05
  • @MichaelKjörling While findstr might work, I would still recommend the method I described in my answer as it's not locale dependent and can find different kind of errors, which can be useful for troubleshooting purposes. – and31415 Aug 11 '14 at 11:38


Search . rather then TTL=:

ping -n %var1% | FIND "." > Test.txt

As you're not looking for a specific text, this method should work in most Windows locales catching multiple error messages without extra effort.

Example output

Pinging with 32 bytes of data:
Reply from bytes=32 time<10ms TTL=128
Ping statistics for

Request timed out

Pinging with 32 bytes of data:
Request timed out.
Ping statistics for

Destination host unreachable

Pinging with 32 bytes of data:
Reply from Destination host unreachable.
Ping statistics for

General failure

Pinging with 32 bytes of data:
General failure.
Ping statistics for

Transmit failed

Pinging with 32 bytes of data:
PING: transmit failed. General failure.
Ping statistics for

Could not find host

Ping request could not find host a.b.c.d. Please check the name and try again.

Further reading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.