if command in Do loop

I

IT Staff

For /F %%i In (%filename%) Do Call :ping4Name %%i

:ping4Name
For /F "Tokens=2" %%a In ('ping -n 1 %1 ^| find /i "Reply"') Do whatever

i want a "if" statement after the do loop. My aim is to find,

a) during the for loop, if able to find /i reply, do whatever
b) during the for loop, if UNABLE to find /i reply, how can i echo "reply
not found"?
 
F

foxidrive

For /F %%i In (%filename%) Do Call :ping4Name %%i

:ping4Name
For /F "Tokens=2" %%a In ('ping -n 1 %1 ^| find /i "Reply"') Do whatever

i want a "if" statement after the do loop. My aim is to find,

a) during the for loop, if able to find /i reply, do whatever
b) during the for loop, if UNABLE to find /i reply, how can i echo "reply
not found"?

Using find "TTL=" is better than find /i "Reply" as there is a "no reply
from" response from ping.


(set flag=)
For /F "Tokens=2" %%a In ('ping -n 1 %1 ^|find "TTL="') Do set flag=%%a
if defined flag (whatever with %flag%) else (echo reply not found)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top