title: Batch ERRORLEVEL ping response
body: <p>I'm trying to use a batch file to confirm a network connection using ping. I want to do batch run and then print if the ping was successful or not. The problem is that it always displays 'failure' when run as a batch. Here is the code: </p>
  
  <pre><code>@echo off
  cls
  ping racer | find "Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),"
  if not errorlevel 1 set error=success
  if errorlevel 1 set error=failure
  cls
  echo Result: %error%
  pause
  </code></pre>
  
  <p>'racer' is the name of my computer. I'm having my computer ping itself so I can eliminate the variable of a poor connection. As I said before, the batch always results in failure. Oddly enough, the program works fine if I copy the code into the command prompt. Does anyone know why the program works fine in the command prompt but doesn't work as a batch?
  Thanks </p>