bat/vbs脚本实现后台运行等功能

bat使用

要点:
1.后台运行
2.相对路径
3.可重复执行

运行执行程序

例1:
nginx启动:

@echo off 
if "%1" == "h" goto begin 
mshta vbscript:createobject("wscript.shell").run("%~nx0 h",0)(window.close)&&exit 
:begin
tasklist | find /i "nginx.exe" >nul 2>nul && goto jump || goto start
:start
cd ./nginx &&start nginx
:jump
echo qidongzhong

例2:
minio启动:

@echo off 
if "%1" == "h" goto begin 
mshta vbscript:createobject("wscript.shell").run("%~nx0 h",0)(window.close)&&exit 
:begin
tasklist | find /i "minio.exe" >nul 2>nul && goto jump || goto start
:start
cd ./minio &&minio server cd ./minio
:jump
echo starting

运行jar包

例:

@echo off 
if "%1" == "h" goto begin 
mshta vbscript:createobject("wscript.shell").run("%~nx0 h",0)(window.close)&&exit 
:begin
set port=80
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do (
 echo kill the process %%m who use the port 
 taskkill /pid %%m -t -f
 goto start
)
:start
cd ./ &&chcp 65001&&java -Dfile.encoding=utf-8 -jar EquipManagePlat.jar

vbs使用

要点:
1.后台运行
2.相对路径
3.批量运行

执行bat文件

例:

set ws=createobject("wscript.shell")

currentpath = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path

ws.run currentpath+"/minio.bat",0

ws.run currentpath+"/nginx.bat",0

ws.run currentpath+"/mqtt.bat",0

ws.run currentpath+"/HikDevServer.bat",0

ws.run currentpath+"/DahDevServer.bat",0

ws.run currentpath+"/EquipManagePlat.bat",0

延时功能

//延迟8s
WScript.sleep 8000
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值