Help with a Windows 7 batch file

I have a series of programs that work together, that are started by clicking a series of four batch (.bat) files. e.g. :

alpha.bat
bravo.bat
charlie.bat
delta.bat

Presently I click each batch file one at a time to start these programs. What I would like to do is create a single batch file that when clicked, launches these four batch files. All of the files involved are located in the same folder.

I have tried this as a batch file:

@echo off
alpha.bat
bravo.bat
charlie.bat
delta.bat
exit

And this:

@echo off
call alpha.bat
call bravo.bat
call charlie.bat
call delta.bat
exit

Both of these will open alpha.bat, but then nothing else. I have tried with and without the “@echo off”, with and without “exit”, so obviously I am missing something. Many of the web sites I have checked mentioned the “call” command, but it isn’t working for me. :frowning:

If alpha.bat has an exit command in it, it probably ends the entire batch file. Remove that command from each of the .bat files and run the first example to see if that helps

The version with calls should work. Get rid of the exit at the end, that’s not needed and may be causing problems. Also temporarily get rid of the @echo off at the beginning so you can see what’s happening.

–Mark

The version with the calls opens only the first .bat file, with the exit removed or not. AFAICT, there’s no exit command in any of the four .bat files.

Try renaming them all to .cmd By having them all as .bat you’re invoking command.com each time so information may be getting lost. And it’s the call version you want.

.bat vs. .cmd hasn’t mattered since NT 4. They now run identically.

As RealityChuck said, there’s probably something in alpha.bat that’s preventing the others from running. If you’re willing to, posting the contents of it would help.

You could also try


@echo off
start "" /wait alpha.bat
start "" /wait bravo.bat
start "" /wait charlie.bat
delta.bat

I can confirm what RealityChuck said. The EXIT command at the end of a batch file causes the command interpreter itself to exit. And it is not necessary in order to end a batch file.

Don’t just guess, open the files and check.

You can simplify that to just start /w alpha.bat, etc.

Also, note that this will result in 5 windows opening. To avoid seeing any windows open up, you may want to use a Windows Scripting file instead of a batch file. Save the following as abcd.vbs in the same folder as the other files, and double click it to run:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run("cmd /c alpha.bat",0,true) 
WshShell.Run("cmd /c bravo.bat",0,true) 
WshShell.Run("cmd /c charlie.bat", 0, true) 
WshShell.Run("cmd /c delta.bat", 0, true)

The “0” is what hides the window, and the “true” makes each command wait before executing the next one. I’m not sure if the cmd /c is necessary, but I’m not where I can test it right now.

Not including a value for window title can lead to unpredictable behavior from start.

You may need to check each of those called batch files to see if they themselves run additional batch files without “call”. A wrong invocation anwywhere down the line could cause the premature termination.

Thanks to all for the replies. None of the suggested resolutions worked (I didn’t try the scripting file). I now believe the problem is that there is indeed something in the first bat file that is preventing the others from opening. Until that is resolved, I don’t believe another .bat file is going to work, plus I am tired of futzing around with it. I may just try to contact the author of the program.

Is this a case of cmd.exe not being exactly compatible with the old command.com?

I was a fairly proficient .BAT programmer back in the bad old DOS days. ISTM that, as cmd.com has become increasingly entrenched and old legacy DOS stuff has been supported more and more poorly, and as old DOS programmers were forced more and more to use cmd.com because command.com either went away or didn’t play well with various Windows versions – I think I’ve seen more and more examples of incompatibilities.

Not that I can give any actual examples, because I always plugged my ears and eyes and went out of my way to pretend I could ignore all that stuff.

One way to debug things like this, if you get the inclination to futz around any more, is to comment out or delete lines and see if you can get it to work. That is, reduce your master .BAT file to simply:


call alpha.bat
call bravo.bat

(you definitely need the call command there), and reduce the alpha.bat script to just one hopefully innocuous line, and see if you can get bravo.bat to run.

If that works, try re-instating lines in alpha.bat, one line at a time, and see if you can spot the line that, when added, causes everything to break.

I spent a lot of years working with a different and totally unrelated scripting language that was driven by a very quirky and poorly documented (and buggy) interpreter, and I spent LOTS AND LOTS of time futzing around.

One more thing to try before giving up–combining my and Number’s suggestions: go for start “” /wait “cmd /c alpha.bat” That will make absolutely sure each batch file runs in a separate process.

(Microsoft themselves say that the title parameter is optional, but I guess I’ll include it just to be safe. I suspect the advice to always use it is just to deal with people who don’t use quotation marks correctly when needed.)

I guess you could also write an AutoHotkey script that would just open the folder window, select each batch file, and press Enter. Or have it open a command prompt, CD to the correct directory, and run the batch files from there.

The start command title argument is optional if and only if the command argument contains no spaces.

Why don’t you just post their code?

This.
All the speculation is kind of pointless, without seeing what is in the four separate batch files.

You shouldn’t even have to call the batch files, you would probably be better off incorporating their actual commands into a single one, but it is hard to say without seeing the actual code in the files.

I assumed he was worried about having permission to share the code. Or maybe he thinks it might be insulting to the person not to give them first crack at fixing it.

Put @echo on at the top of your master .cmd file and see what runs and where it stops. If the other .bat files have @echo off then put rem in front of those statements. Redirect the output of your .cmd to a file if it scrolls too much to fit in your command window.