Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
788 views
in Technique[技术] by (71.8m points)

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

I have a batch file,

bat1.bat
bat2.bat

but it stops at the end of bat1

any clues?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...