赞
踩
start.bat
- @echo off
- setlocal EnableDelayedExpansion
- rem 以管理员方式运行cmd
- PUSHD %~DP0 & cd /d "%~dp0"
- %1 %2
- mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :eof
- :runas
- rem fill in your own execution script
- rem before, close all Java processe
- start taskkill /f /im javaw.exe
- rem 杀死进程停止5秒,防止程序还在运行
- ping 127.0.0.1 -n 3
- rem 启动nacos、redis、minio
- start /d "E:\nacos\bin" startup.cmd
- start /d "E:\redis" startup.bat
- start /d "E:\minio" minio.bat
- rem 启动服务
- rem start cmd /c "title system && java -jar -Dfile.encoding=utf-8 D:\gengbao\basic\ops-system.jar &"
- rem echo 执行完毕,按任意键退出
- rem pause >nul
- exit
-
-
stop.bat
- @echo off
- chcp 65001
- setlocal EnableDelayedExpansion
- rem 以管理方式运行cmd
- PUSHD %~DP0 & cd /d "%~dp0"
- %1 %2
- mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :eof
- :runas
- rem =====================
- rem 多个端口
- rem 会杀死外地占用端口调用本地端口的进程
- rem 设置监听的端口号
- set obj[0]=8848
- set obj[1]=6379
- set obj[2]=9000
- set obj[3]=9031
-
- set port=0
- set pid=0
- rem 从环境中拿去变量obj开头的,遍历,再通过=切割,然后去拿第一二列,%%a就是循环的变量开始
- rem 那么%%a就是例如obj[2],%%b就是例如9000
- echo port : %port%
- for /f "usebackq delims== tokens=1-2" %%a in (`set obj`) do (
- set port=%%b
- for /f "tokens=5" %%m in ('netstat -ano ^| findstr ":%%b"') do (
- set pid=%%m
- )
- if "!pid!"=="0" (
- echo 端口号【!port!】没有被占用,不需要杀死
- ) else (
- taskkill /f /pid !pid!
- echo 端口号【!port!】相关进程已杀死
- )
- set pid=0
- )
- echo 操作完成
- pause
-
- rem =====================
- rem 单个端口
- rem 设置监听的端口号
- rem set port=6379
- rem echo port : %port%
- rem for /f "usebackq tokens=1-5" %%a in (`netstat -ano ^| findstr %port%`) do (
- rem if [%%d] EQU [LISTENING] (
- rem set pid=%%e
- rem )
- rem )
- rem for /f "usebackq tokens=1-5" %%a in (`tasklist ^| findstr %pid%`) do (
- rem set image_name=%%a
- rem )
- rem echo now will kill process : pid %pid%, image_name %image_name%
- rem taskkill /f /pid %pid%
-
- rem =====================
-
- rem 直接关闭所有的cmd窗口,默认的窗口名称是C:\Windows\system32\cmd.exe
- rem taskkill /f /t /fi "windowtitle eq C:\Windows\system32\cmd.exe" /im cmd.exe
- rem 直接某个已知名称的进程
- rem taskkill /f /im notepad.exe
- pause
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。