How do you wait for an exe to complete in batch file?

Solution 1:

Try running

START /WAIT Install.exe

Solution 2:

One shorter way:

Install.exe|more

Also

install|rem

could be used , though with more eventually you'll be able to catch some console output. And this is the reason it works - the piped command waits for input until the .exe is finished


Solution 3:

Either calling the exe directly from the batch file, or using start /wait will work but there is a caveat.

If the exe you call then creates other process, such as calling another exe, and then exits the batch file will continue processing after the called exe has terminated, as it has no knowledge of other processes started by it.

In your case this is a real problem because installers normally extract files from some form of compressed container, which may be embedded in the exe itself, then fire off one of the extracted files and exit. Some installers provide command line parameters which tell the original exe not to exit until the entire installation is complete, so that's something you may want to investigate. Other than that, there's no real way around this with batch files alone and would take a programmatic solution to solve.


Solution 4:

Here is an example using MATLAB! I have assumed that the path setup for MATLAB is done and MATLAB exit is being ensured by the FileName.m file (or user has specified it internally).

echo off
matlab -nosplash /r "FileName.m"
:loop
tasklist /fi "imagename eq MATLAB.exe" |find ":" > nul
if errorlevel 1 goto loop
exit