how to run multiple batch files in serial, in windows command line environment
Asked Answered
U

5

23

I have a batch file,

bat1.bat
bat2.bat

but it stops at the end of bat1

any clues?

Ukase answered 15/1, 2010 at 12:32 Comment(1)
possible duplicate of How to run multiple bat files within a bat fileTasteless
C
43

Use call:

call bat1.cmd
call bat2.cmd

By default, when you just run a batch file from another one controll will not pass back to the calling one. That's why you need to use call.

Basically, if you have a batch like this:

@echo off
echo Foo
batch2.cmd
echo Bar

then it will only output

Foo

If you write it like

@echo off
echo Foo
call batch2.cmd
echo Bar

however, it will output

Foo
Bar

because after batch2 terminates, program control is passed back to your original batch file.

Ctesiphon answered 15/1, 2010 at 12:36 Comment(2)
second example identical to first, but I got the point. Works perfectlyUkase
I think the second example is missing a "call."Panchromatic
N
2

This can happen if bat1.bat stops abnormally (other than just running to the end, like calling exit) and you can work around this by using a fresh cmd.exe to run each bat file:

start /b /wait bat1.bat
start /b /wait bat2.bat

You could omit it for the last one if there won't follow commands in you bat file.

Narrow answered 15/1, 2010 at 12:40 Comment(1)
No, it also happens if the batch terminates normally. Using start here is overkill, though. And you need an extra exit at the end of the sub-batches to kill the cmd process that is spawned. Otherwise you find yourself on a new console after the first batch ran.Ctesiphon
M
1

Something else to look for:

I had a similar issue where I was calling multiple batch files using the call command but it did not pass back the control to the original .bat file.

I found out that I had an exit command at the end of the batch file which closed the DOS window before going back to the original .bat file and finishing the commands there.

Mignon answered 6/3, 2012 at 6:7 Comment(0)
F
1

In order to run the multiple .exe files in one go, firstly you need to create .bat file and then add all of your .exe files as below:

  D:\Data\Feed.exe Books.xml
  D:\Data\Feed.exe Mobile.xml
  D:\Data\Feed.exe Clothes.xml

And then save as something.bat then give it a run with cmd.

Festival answered 12/6, 2012 at 14:17 Comment(0)
M
1

If you want to run batchfiles in sequence you will have to put "start bat1.bat" at the end of each file.

Melmon answered 8/1, 2018 at 14:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.