I'm trying to create a script to execute an exe on shutdown in order to install sp1. my script goes something like (not actual bat script).
If installed GOTO END
Install.exe
END:
My problem is that when it runs, it starts the installer, then finishes the script because the installer's a different process and follows up by shutting down the install process because the computer's shutting down and shutting down the system (at least, that's what i think it's doing.)
Is there any way to tell it to wait until the process it started completes and then shutdown?
Try running
One shorter way:
Also
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.Update
For windows 8 and 10 there's a new tool coming with windows called
scriptrunner
which also can be used for this purpose: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.
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).
I had the problem @John Gardeniers Had or described, where my exe called another exe and terminated, therefor start /wait didn't work. I created a "while loop" to check if its running and then move on once its done. The times can be tweaked to suit your needs.
Similar to @FreeSoftwareServers file, I needed to wait for a program to start that wasn't started by the batch file. Then wait several seconds to start a program that hooks onto the program I'm checking for. If you want the file to timeout after checking a certain amount of times, you could use a counter within the loop to limit the amount of times it loops.
The first TIMEOUT determines how often the loop will repeat, searching for the program. This can be modified to fit your needs.
You can use the the start /wait command. This starts an application and waits for it to end.
Or if you know how long it takes to execute, you can take a look at the sleep command, provided by the Windows Server 2003 Resource Kit Tools . Sleep.exe can be used to pause your batch for any number of seconds to allow the program to install fully before the batch file proceeds to install anything else. There are some programs which ignore the "start /wait" syntax, due to the program itself launching another process, then the sleep.exe is very useful.