Page 1 of 1

Batch script if findstr TTL

Posted: 11 Aug 2018 06:05
by J4ck01
So im trying to write a little script. It should play a sound if my Phone joins my Network.

Code: Select all

@echo off
:A
ping -n 1 xxx.xxx.xxx.xx | findstr TTL && start airsiren.wav
goto A
The Problem is now that if the Phone got detected. It will repeatedly start the Sound. But if done correctly it should only play the sound once and then go back to searching for that Phone. Does anyone know a simple fix? Maybe with an IF conditional?
I haven't been doing much with Batch but i think i got some basic knowledge.
Thanks for your help

Re: Batch script if findstr TTL

Posted: 12 Aug 2018 06:56
by penpen
It should help if you add an "goto :eof" after you have executed playing your sound to avoid the next instruction ("goto A", that results in the endless loop):

Code: Select all

@echo off
:A
echo loop
ping -n 1 xxx.xxx.xxx.xx | findstr TTL && (
	start airsiren.wav
	goto :eof
)
goto A
Alternatively you could also only jump if needed:

Code: Select all

@echo off
:A
echo loop
ping -n 1 xxx.xxx.xxx.xx | findstr TTL && start airsiren.wav || goto :A
penpen