【bat批处理】bat脚本操作

操作系统:win7


1、bat运行完,不让cmd关闭

本文参考自:http://stackoverflow.com/questions/886848/how-to-make-windows-batch-file-pause-when-double-clicked/12036163#12036163

参考:https://blog.csdn.net/zhoulenihao/article/details/47146043


项目中,经常需要写一些批处理文件,比如我们项目中,需要写一个批处理文件,自动打包maven项目,

比如我们打包测试环境的bat文件package-test.bat文件,内容为:

[html]  view plain  copy
  1. @echo -----------------------------------------------------------------------------  
  2. @echo 测试环境打包  
  3. @echo -----------------------------------------------------------------------------  
  4. mvn clean package -Dmaven.test.skip=true -Ptest  
  5. @pause  

网上都说要想让bat文件执行完毕后不关闭,只需要在文件后面加个pause命里即可,它会提示你需要输入,但在我本机测试未起作用,解决该问题的办法是:

修改注册表中:

HKEY_CLASSES_ROOT\batfile\shell\open\command  的值为 cmd /k "%1" %* – 

PS:原值为    "%1" %*

2、删除文件和文件夹的命令

1、rd命令

rd /s /Q c:\temp

会将temp文件夹也删除

2、rd命令+md命令

rd /s /Q c:\temp

md c:\Temp

删除后再重建

3、del命令

del /s /Q c:\temp

只能删除文件,而不能删除子文件夹

4、del命令+rd命令,先刪除文件,再进入temp文件夹删除目录

del /s /Q c:\temp

cd C:\temp

rd /s /q c:\temp


3、附上我为es插件打包写的bat脚本

process1.bat

mvn clean install

process2.bat

echo "es插件 : es插件文件夹创建"

echo "es插件 : 创建文件夹"
md target\elasticsearch

echo "es插件 : 复制文件"
copy /y target\elasticsearch-taste-0.0.1-SNAPSHOT.jar  target\elasticsearch
copy /y src\main\resources\plugin-descriptor.properties target\elasticsearch

echo "es插件 : 打包"
winrar a -ep1 -o+ -inul -r  -iback target\taste-5.4.0.1.zip target\elasticsearch

echo "es插件 : 移动zip"
del F:\taste-5.4.0.1.zip
copy /y target\taste-5.4.0.1.zip  F:\

echo 脚本执行完成  
pause

process3.bat

E:
cd elasticsearch-5.4.1\bin
elasticsearch-plugin remove taste

process4.bat

E:
cd elasticsearch-5.4.1\bin
elasticsearch-plugin install file:F:/taste-5.4.0.1.zip

process5.bat

echo "删除文件夹"
rd /s /Q E:\elasticsearch-5.4.1(1)\elasticsearch-5.4.1\core\src\main\plugins\taste
md E:\elasticsearch-5.4.1(1)\elasticsearch-5.4.1\core\src\main\plugins\taste

xcopy E:\elasticsearch-5.4.1\plugins\taste E:\elasticsearch-5.4.1(1)\elasticsearch-5.4.1\core\src\main\plugins\taste\ /e


猜你喜欢

转载自blog.csdn.net/qq_30141957/article/details/79927437
今日推荐