Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I have a batch file,

bat1.bat bat2.bat 

but it stops at the end of bat1

any clues?

like image 554
Nick Avatar asked Jan 15 '10 12:01

Nick


People also ask

How do I run multiple batch files?

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 ...

Can you run multiple commands in cmd?

Running Multiple Commands as a Single Job We can start multiple commands as a single job through three steps: Combining the commands – We can use “;“, “&&“, or “||“ to concatenate our commands, depending on the requirement of conditional logic, for example: cmd1; cmd2 && cmd3 || cmd4.


1 Answers

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.

like image 74
Joey Avatar answered Sep 30 '22 21:09

Joey