9

I have three bat files I would like to run, in three different directories:

directory/bat1/bat1.bat

directory/bat2/bat2.bat

directory/bat3/bat3.bat

I would like to use one master .bat to start all of the other bats in their directories. I can't use call because I get errors because there are dependencies for each different bat in the directory. I tried using start but that doesn't work either, it just bring up a command prompt withing the folder.

I know this sounds a little confusing but all I want to do is use one single .bat file to run multiple .bat files independent from each other in their own directories.

  • Try cd to each directory in turn then run the batch file ... – DavidPostill Apr 6 '16 at 18:03
  • What would that code look like? Would it be cd "directory/bat1/" start bat1.bat? – JCTechie Apr 6 '16 at 18:03
  • 1
    cd c:\directory\bat1 && bat1.bat then cd c:\directory\bat2 && bat2.bat etc – DavidPostill Apr 6 '16 at 18:05
  • That did not work for me, it only ran the first batch file. – JCTechie Apr 6 '16 at 18:19
13

If you use start, the other bat-files will create new process for each bat, and run them all at the same time.

cd "\directory\bat1\"
start bat1.bat
cd "\directory\bat2\"
start bat2.bat
cd "\directory\bat3\"
start bat3.bat

But if you want to run the next one after the last one is finished, you can use call

cd "\directory\bat1\"
call bat1.bat
cd "\directory\bat2\"
call bat2.bat
cd "\directory\bat3\"
call bat3.bat

don't forget the first \ at the beginning of the cd , otherwise it will try to change the directory into a subdirectory of the current working directory.

8

I found a solution! I used this code in order to get the bat to open the three different bat files independently:

cd "\directory\bat1\"
start bat1.bat
cd "\directory\bat2\"
start bat2.bat
cd "\directory\bat3\"
start bat3.bat
  • 1
    but you wrote in your question "I tried using start but that doesn't work either, it just bring up a command prompt withing the folder." <-- and then you answered it using start. So what was it? – barlop Apr 6 '16 at 20:18
  • Sorry for the confusion I didn't word it correctly. For some reason when I just ran. start \directory\bat1\bat1.bat it just opened a blank command prompt cded into the directory\bat1\ directory. – JCTechie Apr 9 '16 at 11:31
  • I tried this but after calling all the batch file, an endless loop of opening CMDs started to pop out – Kim Carlo Mar 23 '18 at 8:21
1

So i struggled with this problem, and none of these solutions or other ones worked. What I wanted to do in a "master" batch file was access subfolders and run batchfiles in those folders sequentially. This is what I ultimately ended up doing,

cd Folder1
call batch_cmd.bat
cd ..
cd Folder2
call batch_cmd.bat
cd ..

etc. etc. etc.

This format worked fine for me since I was using javascript/nodejs to generate those commands and batch files.

If you want to do something entirely in batch files then I'd suggest you look up powershell scripts instead.

0

For me - it worked as

ECHO Running a batch file..
:: Below is path without double quotes but ends with "\".
cd path-to-the-file1
:: Below is the batch filename without double quotes.
call batch-filename1

:: Below is path without double quotes but ends with "\".
cd path-to-the-file2
:: Below is the batch filename without double quotes.
call batch-filename2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.