title: Windows batch setlocal enabledelayedexpansion call return value
body: <p>There are two (2) Windows batch scripts. The first one will CALL the second one. However, SETLOCAL must be used around the call to the second batch script because ENABLEDELAYEDEXPANSION is needed in a FOR loop.</p>
  
  <p>=== batch1.bat</p>
  
  <pre><code>@echo off
  echo in %0
  set BAT1_VAR=5
  SETLOCAL
      call  batch2.bat
      set|find "BAT"
      echo === before endlocal
  ENDLOCAL
  set|find "BAT"
  echo === after endlocal
  echo === begin exiting %0
  set|find "BAT"
  echo === end exiting %0
  exit /B 0
  </code></pre>
  
  <p>=== batch2.bat</p>
  
  <pre><code>@echo off
  echo in %0
  SET BAT2_VAR=7
  echo === begin exiting %0
  SET|FIND "BAT"
  echo === end exiting %0
  EXIT /B 0
  </code></pre>
  
  <p>===
  The problem is that the variable set by batch2.bat needs to still exist after the return to batch1.bat. This can be resolved by using:</p>
  
  <pre><code>ENDLOCAL &amp; set BAT2_VAR=%BAT2_VAR%
  </code></pre>
  
  <p>HOWEVER, I do not want batch1.bat to need to know the names of variables created by batch2.bat. There might be many and the list may change.</p>
  
  <p>Any ideas to overcome this problem? Thanks.</p>