Scenario 1: Two bat files are in the same directory
Sometimes we need to call another bat file in one bat file, for example, we want to call it in, as follows.
@echo off echo I am … echo now run the call echo over
@echo off echo I am …
Execute in the cmd window, the result is as follows:
I am …
now run the
I am …
over
Through the call command, we can call another bat file, and after execution, we will return to the original bat file to continue 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: The two bat files are not in the same directory
If you want the bat file of the call to be in another directory, we can use the cd /d directory to enter the corresponding directory before calling, and then call it, as follows:
@echo off echo I am … echo now run the cd /d D:\test call echo over
@echo off echo I am …
After execution, the results are as follows:
I am …
now run the
I am …
over
However, it should be noted here that the current directory of the cmd window where the command has been executed is the directory where it is located, not the directory.
Scenario 3: Open a new cmd window to run another bat file
If we want to start a new cmd window to run, we can implement it through the start cmd command, as follows:
@echo off echo I am … echo now run the cd /d D:\test start “” cmd /k call echo over
@echo off echo I am …
After execution, the results are as follows:
In the original cmd window:
I am …
now run the
over
In the new cmd window:
I am …
Here is a brief explanation of the parameters of the command:
start “” cmd /k call
"" is a string representing the name of the newly opened cmd window and can be named at will.
/k means that the newly opened cmd window is saved after executing the command. If you want to close the window after executing the command, use /c
call means a call command, that is, a call file; this command can be enclosed with """, that is: "call"
This is the article about how to call another bat file in a bat file. For more related bat call another bat file, please search for my previous article or continue browsing the related articles below. I hope everyone will support me in the future!