您的位置:首页 > 其它

利用bat脚本进行进程守护

2017-09-13 15:08 232 查看
最近一段时间需要从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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: