title: Prevent batch file from closing after it executes an external .exe program
body: <p>Believe it or not, I've searched all over stackoverflow and Google and can't find an answer to this that works for me.</p>
  <p>(Windows 7 64-bit) I'm trying to create a batch file that runs multiple programs, one at a time. Simple, right? It works great until it runs the first <code>.exe</code> program. After the GUI of the <code>.exe</code> program closes, the batch file/cmd window also closes. I don't want it to close; I want the rest of the batch file to run.</p>
  <p>Inside the batch file, I've tried the following methods, but none of them prevent the batch file from closing:</p>
  <ol>
  <li><code>Git-1.9.5-preview20141217.exe</code></li>
  <li><code>Git-1.9.5-preview20141217.exe</code><br />
  <code>pause</code></li>
  <li><code>call Git-1.9.5-preview20141217.exe</code><br />
  <code>pause</code></li>
  <li><code>start Git-1.9.5-preview20141217.exe</code><br />
  <code>pause</code></li>
  <li><code>start &quot;&quot; /wait Git-1.9.5-preview20141217.exe</code><br />
  <code>pause</code></li>
  <li><code>start &quot;&quot; /w Git-1.9.5-preview20141217.exe</code><br />
  <code>pause</code></li>
  <li><code>start &quot;&quot; /w /b Git-1.9.5-preview20141217.exe</code><br />
  <code>pause</code></li>
  </ol>
  <p>Does anyone know another method I can try? Maybe I should just call a powershell command or even translate the whole batch file to powershell, but I was trying to avoid powershell so that this script would work on multiple versions of Windows.</p>
  <h3>EDIT</h3>
  <p>I should also mention that with the methods above, the script closes <em>before</em> the <code>pause</code> command can be executed.</p>
  <h3>EDIT</h3>
  <p>Here's the full script with the rest of the <code>.exe</code> programs:</p>
  <pre><code>:Git
  @echo off
  (
  echo.
  echo.
  echo DOWNLOADING GIT...
  )
  powershell -Command &quot;(New-Object Net.WebClient).DownloadFile('http://github.com/msysgit/msysgit/releases/download/Git-1.9.5-preview20141217/Git-1.9.5-preview20141217.exe', 'Git-1.9.5-preview20141217.exe')&quot;
  (
  echo.
  echo.
  echo LAUNCHING GIT INSTALLATION PROGRAM...
  echo.
  echo !IMPORTANT! WHEN YOU REACH THE SCREEN 'Adjusting your PATH environment',
  echo SELECT 'Use Git from the Windows Command Prompt'.
  echo KEEP ALL OTHER OPTIONS AT THE DEFAULT SETTING.
  echo.
  echo AFTER READING THE INSTRUCTIONS ABOVE, PRESS ANY KEY TO CONTINUE
  )
  pause
  Git-1.9.5-preview20141217.exe
  pause
  GOTO CheckOS
  
  :CheckOS
  IF EXIST &quot;%PROGRAMFILES(X86)%&quot; (GOTO 64BIT) ELSE (GOTO 32BIT)
  
  :32BIT
  (
  echo.
  echo.
  echo 32 BIT
  echo.
  echo DOWNLOADING TORTOISEHG (MERCURIAL)...
  )
  powershell -Command &quot;(New-Object Net.WebClient).DownloadFile('http://bitbucket.org/tortoisehg/files/downloads/tortoisehg-3.2.4-x86.msi', 'tortoisehg-3.2.4-x86.msi')&quot;
  (
  echo.
  echo.
  echo LAUNCHING TORTOISEHG INSTALLATION PROGRAM...
  )
  tortoisehg-3.2.4-x86.msi
  GOTO MingW
  
  :64BIT
  (
  echo.
  echo.
  echo 64 BIT
  echo.
  echo DOWNLOADING TORTOISEHG (MERCURIAL)...
  )
  powershell -Command &quot;(New-Object Net.WebClient).DownloadFile('http://bitbucket.org/tortoisehg/files/downloads/tortoisehg-3.2.4-x64.msi', 'tortoisehg-3.2.4-x64.msi')&quot;
  (
  echo.
  echo.
  echo LAUNCHING TORTOISEHG INSTALLATION PROGRAM...
  )
  tortoisehg-3.2.4-x64.msi
  GOTO MingW
  
  :MingW
  (
  echo.
  echo.
  echo DOWNLOADING MINGW...
  )
  powershell -Command &quot;(New-Object Net.WebClient).DownloadFile('http://downloads.sourceforge.net/project/mingwbuilds/mingw-builds-install/mingw-builds-install.exe?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmingwbuilds%2F%3Fsource%3Dtyp_redirect&amp;ts=1422376004&amp;use_mirror=iweb', 'mingw-builds-install.exe')&quot;
  (
  echo.
  echo.
  echo LAUNCHING MINGW INSTALLATION PROGRAM...
  )
  mingw-builds-install.exe
  (
  echo.
  echo.
  echo DONE! PRESS ANY KEY TO CLOSE.
  )
  pause
  GOTO END
  
  :END
  </code></pre>
  <p>For the lines that run the external <code>.exe</code> program, I've tried all 7 forms of the command that were listed at the beginning of this question, yet the script always closes before reaching the next <code>pause</code> command. I've also tried using <code>cmd.exe /c</code> and <code>cmd.exe /k</code> from the suggestions below, but unfortunately the script still quits before reaching the <code>pause</code> command.</p>
  <h3>EDIT</h3>
  <p><s>I figured out the problem (though not how to fix it). If I remove these lines:</p>
  <pre><code>GOTO CheckOS
  
  :CheckOS
  IF EXIST &quot;%PROGRAMFILES(X86)%&quot; (GOTO 64BIT) ELSE (GOTO 32BIT)
  
  :32BIT
  </code></pre>
  <p>so that the following commands are under the same batch label, it works! But I'm not sure why including the <code>:CheckOS</code> label causes it to break. I've used this label in other batch scripts before, and they worked fine.</s></p>
  <p>Nevermind, sorry. :S This only worked if the program had already been run. If it had already been run, a &quot;modify, repair, or remove&quot; screen popped up instead of an &quot;install&quot; screen. Apparently only the &quot;install&quot; screen closes the <code>cmd.exe</code> window.</p>
  <h3>FINAL EDIT</h3>
  <p>The parentheses were the problem. After removing them, everything else worked. Method number 1 at the beginning of this question works after removing the parentheses.</p>