windows下bat,检测进程是否开启,并启动

(1)goto命令执行循环

(2)tasklist|findstr -i "mysqld.exe"

检测进程是否存在

(3)start "" "D:/a_wnmps/webserver/mysql/bin/mysqld.exe"

执行命令,后面的第一个"",用来允许第二个"..."中有空格 

(4)执行不同目录下的bat,两步

1.先 cd /d "D:\a_wnmps\webserver\nginx"    // 跳转目录
2.再 Call start_nginx.bat                                // 执行bat文件

最后,cd /d "D:\a_file"  // 返回原来的目录,不然命令行上没东西

(5)choice /t 300 /d y /n > nul

延时,/t后面的300指300秒,也可以用:

ping -n 300 127.0.0.1 >nul   延时,-n后面的300指300秒

@echo off
title restart bbs

set BASE_DIR=%~dp0
%BASE_DIR:~0,2%


:again

tasklist|findstr /i "mysqld.exe" > nul
if ERRORLEVEL 1 (
	echo mysqld is off in %Date:~0,4%-%Date:~5,2%-%Date:~8,2% %Time:~0,2%:%Time:~3,2%
	start "" "D:/a_wnmps/webserver/mysql/bin/mysqld.exe"
)

tasklist|findstr /i "nginx.exe" > nul
if ERRORLEVEL 1 (
	echo nginx is off in %Date:~0,4%-%Date:~5,2%-%Date:~8,2% %Time:~0,2%:%Time:~3,2%
	cd /d "D:\a_wnmps\webserver\nginx" 
	Call start_nginx.bat
)

tasklist|findstr /i "xxfpm.exe" > nul
if ERRORLEVEL 1 (
	echo xxfpm is off in %Date:~0,4%-%Date:~5,2%-%Date:~8,2% %Time:~0,2%:%Time:~3,2%
	cd /d "C:\Users\administrator\Desktop\xxfpm\bin" 
	Call start_xxfpm.bat
)

cd /d %BASE_DIR%

choice /t 300 /d y /n > nul  

goto again

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值