当前位置:   article > 正文

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

bat脚本后台运行

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

例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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

运行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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

延时功能

//延迟8s
WScript.sleep 8000
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/思考机器4/article/detail/61539
推荐阅读
相关标签
  

闽ICP备14008679号