1.

Solve : Reading in ping output using batch file?

Answer»

Hey guys,

I'm trying to write a batch file that pings an address and if the average round trip is > 0ms then run a text file.

The only prob i have is i don't know how to read int he output from the ping command.
Code: [Select]: Loop
Sleep 3 h
ping 127.0.0.1
// If the average round trip is > 0ms start OverTime.txt
:End
Thanks for any help,
John

one way is to output to a temporary file USING >>
then open that file, search for the time and do your other processes...Hey Ghostdog,

what command should i USE to search the text file?

Like if i output the results of the ping to "test.txt" how do i search through that for the time?

Thanks,
Johncheck out findstr /?
eg for my case i have these in a file.

Pinging 127.0.0.1 with 32 BYTES of data:

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

Say i wish to find time<1ms, so

Code: [Select]C:\>findstr "time<1ms" file.txt
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

C:\>echo %errorlevel%
0

C:\>findstr "time<10ms" file.txt

C:\>echo %errorlevel%
1

If you prefer to ITERATE each line through the file, use the for loop. Check out for /?

well, may not be the best way to do what you want, but this wat i could think of now...
maybe some other gurus can help you..Thanks a lot ghostdog, appreciate it



Discussion

No Comment Found