利用bat脚本进行进程守护

最近一段时间需要从youtube将一些有用的时间较长的直播转存成视频存在本地,就使用streamlink进行完成该工作,但是由于网络的不稳定,有时候在运行的时候就会因为网络超时而退出,就写了下面的脚本来进行对streamlink进程进行守护,在streamlink进程奔溃后对其进行重启。

我在测试的时候使用的是windows系统自带的notepad记事本程序,一些按照预想的进行的,在脚本中注释掉的内容,接下来等下次streamlink结束的时候就是这个脚本上场的时候了。

@echo off

::set _task=notepad.exe
set _task=streamlink

goto CHECK

:CHECK
REM  Check whether the process is running 
qprocess  >tasklist_tmp.txt

type tasklist_tmp.txt | findstr /i %_task%
  
if %errorlevel% ==0  goto SLEEP

if %errorlevel% ==1  goto RUN


:RUN

set _suffix=.avi
set _command=streamlink  https://www.youtube.com/watch?v=psfFJR3vZ78  best  -o 
::set _current_time=%date:~0,4%%date:~5,2%%date:~8,2%-%time:~0,2%%time:~3,2%%time:~6,2% 
::set _service=%_command%%_current_time%%_suffix%

rem echo 获取当前日期字符串
for /f "tokens=1,2,3 delims=/- " %%a in ("%date%") do @set D=%%a%%b%%c
rem echo 获取当前时间字符串
for /f "tokens=1,2,3 delims=:." %%a in ("%time%") do @set T=%%a%%b%%c
rem echo 如当前小时小于10,将空格替换为0
set T=%T: =0%
rem echo 显示输出日期时间字符串
echo %D%%T%

set _service=%_command%E:\jackson_town_square-%D%%T%%_suffix%

echo %_service%
::start c:\windows\system32\notepad.exe
start %_service%
echo The program started at %time%>>deamon.log

:SLEEP
REM  sleep for 10 minutes
echo %time% The Program is Running,sleep for 10s...
echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs 
cscript //b //nologo %tmp%\delay.vbs 10000

goto CHECK

转载于:https://my.oschina.net/zhangwenwen/blog/1536763

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值