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 10 /d y /n > nul

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

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

@echo off
title restart bbs
:again

tasklist|findstr -i "mysqld.exe"
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"
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"
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 "D:\a_file" 

choice /t 300 /d y /n > nul  

goto again

猜你喜欢

转载自blog.csdn.net/u013595395/article/details/99288683