Batch script if findstr TTL

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
J4ck01
Posts: 1
Joined: 11 Aug 2018 06:02

Batch script if findstr TTL

#1 Post by J4ck01 » 11 Aug 2018 06:05

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

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch script if findstr TTL

#2 Post by penpen » 12 Aug 2018 06:56

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

Post Reply