Batch file error: "cant be processed syntactically at this point" -


my batch-file program crashes @ same point. happens before crashes this:

ping -n 6 127.0.0.1 1>nul: 2>nul:  -n cant processed syntactically @ point.  if ping -n 1 127.0.0.1|find "(0" >nul && goto loop 

and window closes.

could maybe me fix problem? whole script:

@setlocal enableextensions enabledelayedexpansion  :loop  set ipaddr=127.0.0.1  ping -n 6 %ipaddr% >nul: 2>nul:  if ping -n 1 %ipaddr%|find "(0%" >nul && goto loop  echo connection lost  start "" http://www.google.com   else if ping -n 1 %ipaddr%|find "(100%" >nul && goto loop  echo connection ok  taskkill /fi "windowtitle eq google*" goto loop  endlocal 

here advanced version 2 blocks of code executed dependent of whether connection ok or lost.

@setlocal enableextensions enabledelayedexpansion set ipaddr=127.0.0.1 :loop ping -n 6 %ipaddr% >nul: 2>nul: ping -n 1 %ipaddr%|find "(0%" >nul && (   echo connection ok   taskkill /fi "windowtitle eq google*"  ) || (   echo connection lost   tasklist /v /fi "windowtitle eq google*" || start "" http://www.google.com ) goto :loop 

this "conventional way" %errorlevel% , if- else (same logic, above shorter way of doing it):

@setlocal enableextensions enabledelayedexpansion set ipaddr=127.0.0.1 :loop ping -n 6 %ipaddr% >nul: 2>nul: ping -n 1 %ipaddr%|find "(0%" >nul  if %errorlevel%==0 (   echo connection ok   taskkill /fi "windowtitle eq google*"  ) else (   echo connection lost   tasklist /v /fi "windowtitle eq google*" || start "" http://www.google.com ) goto :loop 

i took set ipaddr... out of loop. no need again , again.

(just wondering, if google reachable, if connection got lost...)

edit reflect last comment. bit enhanced, action happens, if connection status changes. delete "log" function if don't need it, or redirect them file, if like.

@echo off setlocal enabledelayedexpansion set ipaddr=127.0.0.1 set "status=undefined"  :loop ping -n 2 %ipaddr% >nul: 2>nul: ping -n 1 %ipaddr%|find "(0%" >nul && (    set oldstatus=!status!   set status=online   if !status! neq !oldstatus! (     echo %date% %time% connection switched !oldstatus! !status!     taskkill /fi "windowtitle eq google*" >nul 2>&1   )  ) || (    set oldstatus=!status!   set status=offline   if !status! neq !oldstatus! (     echo %date% %time% connection switched !oldstatus! !status!     start "" http://www.google.com   )  ) goto :loop 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -