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 cmd bat file

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to call another bat file in cmd bat file". In daily operation, I believe that many people have doubts about how to call another bat file in cmd bat file. Xiaobian consulted all kinds of information and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "how to call another bat file in cmd bat file". Next, please follow the editor to study!

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 off echo I am a.bat... Echo now run the b.bat call b.bat echo over

B.bat

@ echo off echo 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 off echo I am a.bat... Echo now run the b.bat cd / d D:\ test call b.bat echo over

B.bat

@ echo off echo 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 off echo I am a.bat... Echo now run the b.bat cd / d D:\ test start "" cmd / k call b.bat echo over "

B.bat

@ echo off echo 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 the execution of the command. If you want to close the window after execution, use / c call b.bat to represent the call command, that is, call the b.bat file; the command can be enclosed in "", that is, "call b.bat". At this point, the study on "how to call another bat file in the cmd bat file" is over. I hope you can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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