if command in Do loop

  • Thread starter Thread starter IT Staff
  • Start date Start date
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"?
 
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)
 
Back
Top