run exe format in batch file
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"
C:
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...
Related videos on Youtube
user44509
Updated on September 17, 2022Comments
-
user44509 almost 2 years
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
-
user44509 almost 14 yearsHere 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"
-
JBirch almost 14 yearsIt is imperative you include the
/wait
parameter if you wantmodeler.exe
to run only aftervcvarsall.bat
has finished, and you only wantvcvarsall.bat
to run only aftervsvars32.bat
has finished.
-
-
JBirch almost 14 yearsaumha.org/a/batches.php is a nice resource dealing with batch files.
-
user44509 almost 14 yearsIt doesn't work,just the batch opened 3 cmds,that s it
-
JBirch almost 14 yearsI'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. -
user44509 almost 14 yearsI added those addresses to my environment variables,although I expected to address them in batch file, I copied my batch file in question
-
user44509 almost 14 yearsyeah,later I added /wait nicely. the thing is whenever I add address it s not working ,just open new windows. but by adding to environment variables it solved
-
JBirch almost 14 yearsThat's interesting! I'm afraid I don't know enough about batch files to comment on why that might be - why it works if it's part of the environmental variables but why you can't specify it directly. I'll have to have a play around in the future. Thanks for the clarification on what the exact solution was :)
-
user44509 almost 14 yearsyeah,that s a bit weired, anyway thanks for your hand, I would let you know if i find out what's going on
-
nhinkle almost 14 yearsWere 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"
.