Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make a batch file,which run 3 executable file respectively: A.exe B.exe C.exe

P.S: A.exe gotta finish its job then batch file go for B.exe and finally C.exe

share|improve this question
Here is my batch file: echo programs are processing .... echo. echo First Phase START "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vsvars32.bat" echo 2nd Phase START "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" echo Final phase START "C:\Program Files\OPNET\16.0.A\sys\pc_intel_win32\bin\modeler.exe" – user44509 Aug 16 '10 at 14:23
It is imperative you include the /wait parameter if you want modeler.exe to run only after vcvarsall.bat has finished, and you only want vcvarsall.bat to run only after vsvars32.bat has finished. – JBirch Aug 16 '10 at 14:43
up vote 8 down vote accepted

A three line batch file would do. For example, a batch file called mybatch.bat...

START /wait notepad.exe
START /wait sol.exe
START /wait thirdExecutable.exe

the /wait parameter can also be replaced with /w, and instructs the batch script to wait until the executable terminates before proceeding to the next stage. Thus, you may elect not to use this parameter on the third line. Doing so would only cause the cmd window to remain open until the third executable has terminated.

EDIT TO ADDRESS COMMENT: I'm afraid that works for me. You might also make sure you replace the executable with the exact path to your executable files - for example, if A.exe was located in C:\MyFolder\, you would modify the first line to be START /wait C:\MyFolder\A.exe. This isn't required if the executables are in any folder referenced in the environmental variable %PATH% or are in the same folder as the batch file. I don't think this is your issue.

I wonder if those three cmd windows the batch opened were indeed the executable files you wished to run? The main window that opens with the batch file will echo the commands it is issuing, and will also display if it cannot execute the commands it is given. If you didn't get a pop-up error alert, then your batch file is finding and successfully running those three executables you specify.

As the link I provided also says, you may also use the parameter /minimized - or equivalently /m - in addition to /wait to execute the files minimised by default. This might make things perhaps a bit neater and look like what you were expecting.

As it stands, I think it is working exactly as intended. Exactly as you described the issue, anyway.

SECOND EDIT: Given your batch file, I've done the small changes necessary for it to do what you want. I don't actually know what you want to echo with the very beginning, but it should display enough information.

ECHO "programs are processing...." 
ECHO "First Phase" 
START /w "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vsvars32.bat" 
ECHO "Second Phase" 
START /w "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
ECHO "Final phase"
START /w "C:\Program Files\OPNET\16.0.A\sys\pc_intel_win32\bin\modeler.exe" 

Does this work as intended?

FINAL EDIT: You can get around the environmental variable thing, if you'll ever need to run this batch file somewhere where you don't have permissions to modify them.

ECHO "programs are processing...." 
ECHO "First Phase" 
cd "\Program Files\Microsoft Visual Studio 9.0\VC\bin
START /w vsvars32.bat
ECHO "Second Phase"
cd ..
START /w vcvarsall.bat
ECHO "Final phase"
cd "\Program Files\OPNET\16.0.A\sys\pc_intel_win32\bin"
START /w modeler.exe

And that seems to get around the problem on my end. Ugly as anything, but batch files never did seem to be intrinsically beautiful...

share|improve this answer is a nice resource dealing with batch files. – JBirch Aug 16 '10 at 13:14
It doesn't work,just the batch opened 3 cmds,that s it – user44509 Aug 16 '10 at 14:08
I've added an edit to address your issue. It was too long to fit as a comment. Suffice it to say, it does work as intended. Those three cmd windows are your executable files. If this isn't exactly what you wanted, then please amend your question accordingly. – JBirch Aug 16 '10 at 14:32
I added those addresses to my environment variables,although I expected to address them in batch file, I copied my batch file in question – user44509 Aug 16 '10 at 14:41
Were you using quotes around the path? That'll break it - the full syntax for the start command is start.exe "title" /wait path. It gets confused if you specify the path in quotes without specifying a title, because it thinks the path is the title. So, you would need to specify an arbitrary title, e.g. start "new program" /wait "C:\thing\stuff.exe". – nhinkle Aug 17 '10 at 18:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .