Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call another bat file in a bat file

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to call another bat file in the bat file, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Scenario 1: two bat files in the same directory

Sometimes we need to call another bat file in one bat file, for example, we want to call b.bat in a.bat, as follows.

A.bat

@ echo offecho I am a.bat... Echo now run the b.batcall b.batecho over

B.bat

@ echo offecho I am b.bat...

Execute a.bat in the cmd window and the result is as follows:

I am a.bat...

Now run the b.bat

I am b.bat...

Over

With the call command, we can call another bat file, and then return to the original bat file after execution. But there is a problem here, that is, the two bat files must be in the same directory, otherwise the bat file you want to call will not be found.

Scenario 2: two bat files are not in the same directory

If you want the bat file of call to be in another directory, we can use the cd / d directory to enter the corresponding directory before call, and then call it, as follows:

A.bat

@ echo offecho I am a.bat... Echo now run the b.batcd / d D:\ testcall b.batecho over

B.bat

@ echo offecho I am b.bat...

After execution, the results are as follows:

I am a.bat...

Now run the b.bat

I am b.bat...

Over

However, it is important to note that the current directory of the cmd window that finished executing the command is the directory where b.bat is located, not the directory of a.bat.

Scenario 3: open a new cmd window to run another bat file

If we want to launch a new cmd window to run b.bat, we can do this through the start cmd command, as follows:

A.bat

@ echo offecho I am a.bat... Echo now run the b.batcd / d D:\ teststart "" cmd / k call b.batecho over "

B.bat

@ echo offecho I am b.bat...

After execution, the results are as follows:

In the original cmd window:

I am a.bat...

Now run the b.bat

Over

In the new cmd window:

I am b.bat...

Here is a brief explanation of the parameters of the command:

Start "" cmd / k call b.bat

"" is a string that represents the name of the newly opened cmd window, which you can name at will.

/ k means that the newly opened cmd window saves the open state after executing the command. If you want to close the window, use / c

Call b.bat stands for the call command, that is, to invoke the b.bat file; the command can be enclosed in "", that is, "call b.bat"

The above is all the contents of the article "how to call another bat file in a bat file". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report