title: batch script exits on SET
body: <p>I am trying to write a batch script that executes the following set of commands:</p>
  
  <pre><code>for /f "delims=: tokens=2" %I in ('ipconfig^|findstr /I /C:"Default Gateway . . . . . . . . . : 192.168"') do SET gw=%I
  if "%gw%" == " 192.168.1.1" \\server\script.cmd
  if "%gw%" == " 192.168.2.1" \\server\script2.cmd
  if "%gw%" == " 192.168.3.1" \\server\scripts3.cmd
  </code></pre>
  
  <p>The problem is when the FOR statement runs the SET command the script will exit before the rest of the commands are ran. </p>
  
  <p>What I need the batch script to do is set the 'gw' variable and then continue with the rest of the commands.</p>
  
  <p>FYI: The script is suppose to parse the gateway of the computer and then run another script based on that info. All of the commands run from within the 'cmd' window when executed separately.</p>