A .bat script that can execute cmd commands
Recently, because of work, I need to start several programs of reids, zookeeper, and tomcat on Windows every morning. It feels a bit cumbersome over time, so I wanted to write a script to solve the problem with one click. After some Baidu, I summarized the following content :
1. First, you need to create a .bat file. You can create a new notepad first, and then change the suffix name to ".bat", such as "test.bat".
2. Then edit the content
@echo off
start cmd /k "cd/d D:\AA\service\redis &&redis-server.exe redis.windows.conf &&taskkill /f /t /im cmd.exe"
start cmd /k "cd/d D:\AA\service\zookeeper-3.4.8\bin &&zkServer.cmd &&taskkill /f /t /im cmd.exe"
start cmd /c "cd/d D:\tmp\tomcat8\bin &&startup.bat"
3. Save this file, and then double-click this file.
Explanation:
start is used to start an application. The usage is: start program name
cmd /k means that the window will not be closed after the command after
cmd is executed cmd /c means that the command window will be closed after the cmd command is executed
About the @echo off command:
echo off Turn off the display of other commands (but not including this command)
@echo off Turn off the display of all commands (@Turn off the display of subsequent commands)
Or check the following link
https://blog.csdn.net/fly_as_tadpole/article/details/85177379
https://blog.csdn.net/lindaydk/article/details/6305641
for detailed explanation
If you need to close, you can use:
command taskkill /f /t /im plus the program to be closed
@echo off
start cmd /k "taskkill /f /t /im java.exe &&taskkill /f /t /im cmd.exe"
This shutdown method is effective for some single-process programs, but invalid for multi-process programs.
Regarding the "&&taskkill /f /t /im cmd.exe" statement in the above command, I don't quite understand its role. After many tests, I found that adding this statement does not seem to have any effect.