[服务器]进程守护

该文章讲述了如何在批处理(BAT)脚本中利用%errorlevel%检查命令执行状态,特别是针对命令行错误如9009进行处理。通过示例脚本展示了如何轮询检查WeChat.exe是否运行,并根据其状态决定是否启动,体现了批处理脚本在自动化任务中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

bat脚本中常用%errorlevel%表达上一条命令的返回值,即命令执行状态码、也称命令退出码

一般上一条命令的执行结果返回的值只有两种,0和非0 (如常见的1,2,4,5,9009等等),0一般会被视为成功,非0为失败或者异常

对于9009,在cmd中经常会发生输入的命令错误,或者不存在的命令,这时就会返回9009这种状态码,

10秒轮询

:start

choice /t 10 /d y /n >nul
tasklist|find /i " WeChat.exe" 

if %errorlevel%==0 ( 
	echo 微信已存在
) else (
	echo 微信不存在,启动
                start D:\WeChat\WeChat.exe
)
goto start 
:start
choice /t 10 /d y /n>nul
tasklist|find /i " WeChat.exe" 

if %errorlevel%==0 ( 
	echo wechat start
) else (
	echo  wechat not
	start D:\WeChat\WeChat.exe
)
goto start 

简单粗暴

:Restart
start /i /wait D:\WeChat\WeChat.exe
start /i /wait D:\WXWork\WXWork.exe
goto Restart
:Restart
tasklist|find /i " WeChat.exe"  || start /d "D:\WeChat\" WeChat.exe && start /d "D:\WeChat\" WeChat.exe
goto Restart

直接点

:Restart
start /wait C:\pan\软件\WM系统服务器009\WM服务器程序.exe
goto Restart
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值