当前位置:   article > 正文

windows bat脚本 启动和停止程序_bat 停止

bat 停止

start.bat

  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. rem 以管理员方式运行cmd
  4. PUSHD %~DP0 & cd /d "%~dp0"
  5. %1 %2
  6. mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :eof
  7. :runas
  8. rem fill in your own execution script
  9. rem before, close all Java processe
  10. start taskkill /f /im javaw.exe
  11. rem 杀死进程停止5秒,防止程序还在运行
  12. ping 127.0.0.1 -n 3
  13. rem 启动nacos、redis、minio
  14. start /d "E:\nacos\bin" startup.cmd
  15. start /d "E:\redis" startup.bat
  16. start /d "E:\minio" minio.bat
  17. rem 启动服务
  18. rem start cmd /c "title system && java -jar -Dfile.encoding=utf-8 D:\gengbao\basic\ops-system.jar &"
  19. rem echo 执行完毕,按任意键退出
  20. rem pause >nul
  21. exit

stop.bat

  1. @echo off
  2. chcp 65001
  3. setlocal EnableDelayedExpansion
  4. rem 以管理方式运行cmd
  5. PUSHD %~DP0 & cd /d "%~dp0"
  6. %1 %2
  7. mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :eof
  8. :runas
  9. rem =====================
  10. rem 多个端口
  11. rem 会杀死外地占用端口调用本地端口的进程
  12. rem 设置监听的端口号
  13. set obj[0]=8848
  14. set obj[1]=6379
  15. set obj[2]=9000
  16. set obj[3]=9031
  17. set port=0
  18. set pid=0
  19. rem 从环境中拿去变量obj开头的,遍历,再通过=切割,然后去拿第一二列,%%a就是循环的变量开始
  20. rem 那么%%a就是例如obj[2],%%b就是例如9000
  21. echo port : %port%
  22. for /f "usebackq delims== tokens=1-2" %%a in (`set obj`) do (
  23. set port=%%b
  24. for /f "tokens=5" %%m in ('netstat -ano ^| findstr ":%%b"') do (
  25. set pid=%%m
  26. )
  27. if "!pid!"=="0" (
  28. echo 端口号【!port!】没有被占用,不需要杀死
  29. ) else (
  30. taskkill /f /pid !pid!
  31. echo 端口号【!port!】相关进程已杀死
  32. )
  33. set pid=0
  34. )
  35. echo 操作完成
  36. pause
  37. rem =====================
  38. rem 单个端口
  39. rem 设置监听的端口号
  40. rem set port=6379
  41. rem echo port : %port%
  42. rem for /f "usebackq tokens=1-5" %%a in (`netstat -ano ^| findstr %port%`) do (
  43. rem if [%%d] EQU [LISTENING] (
  44. rem set pid=%%e
  45. rem )
  46. rem )
  47. rem for /f "usebackq tokens=1-5" %%a in (`tasklist ^| findstr %pid%`) do (
  48. rem set image_name=%%a
  49. rem )
  50. rem echo now will kill process : pid %pid%, image_name %image_name%
  51. rem taskkill /f /pid %pid%
  52. rem =====================
  53. rem 直接关闭所有的cmd窗口,默认的窗口名称是C:\Windows\system32\cmd.exe
  54. rem taskkill /f /t /fi "windowtitle eq C:\Windows\system32\cmd.exe" /im cmd.exe
  55. rem 直接某个已知名称的进程
  56. rem taskkill /f /im notepad.exe
  57. pause

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/76236
推荐阅读
相关标签
  

闽ICP备14008679号