Question

I want to run ONE batch file, that starts 4 other batch files. Problem: Only the first CMD file gets executed.

I looked at a similar questions posted here: How to run multiple .BAT files within a .BAT file
And here: How do I launch multiple batch files from one batch file with dependency?

The difference with my question is that i pass along a RootPath for each CMD file.

Examples given in other posts: 
call msbuild.bat
call unit-tests.bat
call deploy.bat

My code:
SET RootPath="G:\Dev Folder\Framework\MainFolder\SubFolder\JOBS\"
CALL %RootPath%Account.CMD
CALL %RootPath%Customer.CMD
CALL %RootPath%Contract.CMD
CALL %RootPath%Location.CMD

This Master.CMD file containing the code is not in the same directory as the Account/ Customer/ Contract/ Location cmd files, that's why i'm passing an absolute path. The first command runs just fine. And then i get the error:

'..\Customer.CMD ' is not recognized as en internal or external command, operable program or batch file.
'..\Contract.CMD ' is not recognized as en internal or external command, operable program or batch file.
'..\Location.CMD ' is not recognized as en internal or external command, operable program or batch file.

I'm not able to deduce a solution from the other Batch posts on stackoverflow. I'm new to this language, please excuse me if i've overlooked something.

Any and all help is welcome.

Was it helpful?

Solution

This looks like your Account.cmd resets RootPath. Env variables are (session) global, unless you isolate them with setlocal. To resolve you could change names (as you did) or use setlocal in your batch files. It's generally good practice anyway as it helps to avoid unexpected/unwanted side effects. Here is a quote from help setlocal:

Begins localization of environment changes in a batch file. Environment changes made after SETLOCAL has been issued are local to the batch file. ENDLOCAL must be issued to restore the previous settings. When the end of a batch script is reached, an implied ENDLOCAL is executed for any outstanding SETLOCAL commands issued by that batch script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top