[GLLUG] (OT) Win32 ping and errorlevel ?

Adam McDougall mcdouga9@egr.msu.edu
Fri, 1 Feb 2002 17:15:17 -0500


On Fri, Feb 01, 2002 at 04:21:56PM -0500, Melson, Paul wrote:

  Sorry for the Microsoftish question, but it seems like someone might have stumbled across this issue already.
  
  Does anybody know about PING.EXE for WinNT/2K and its errorlevels?  I'm trying to script a Scheduled Task that would check to see if a network connection (VPN in this case, but that's irrelevant) is up before launching MOBSYNC.EXE.  Here is the offending code:
  
  @echo off
  ping -n 5 10.0.0.8				# This sends 5 packets to overcome any ARP or lag issues.
  ping -n 1 -w 5000 10.0.0.8			# This sends 1 packet w/ 5sec wait time to assure the IP is up.
  if not errorlevel 0 goto Fail			# If there is any errorlevel other than 0, we have a problem.
  
Try:
if not errorlevel==0 goto Fail

  
  But we have a problem, anyway.  It seems to be skipping the "if" statement.  Regardless of whether or not it's able to ping the host, it tries to run the commands to connect to the host and sync up.  Is there something wrong w/ my syntax?  I chose to do it this way because I was unable to find any documentation on PING.EXE and specific errorlevels.  Or does PING.EXE simply not return errorlevels?  I would do this w/ a shell script in Cygwin, but Cygwin uses the same ping program, and it seems like such a simple task to use Ping.pm for.  Any help you can provide is greatly appreciated.
  
  PS - the actual batch file doesn't have the #-marked comments.
  
  Thanks,
  PaulM