通过冷却每小时自动重启一个程序

时间:2014-01-14 09:28:23

标签: batch-file

我正在寻找能够实现这一序列的脚本。

  1. 每三个小时关闭一次程序;
  2. 等待30秒;
  3. 重启计划;
  4. 你能帮我解决这个问题吗? 非常感谢!

    此致

3 个答案:

答案 0 :(得分:4)

此处有一条帖子Batch file - restart program after every 20 minutes

@echo off
:loop
start yourtarget.exe ...
timeout /t 1200 >null
taskkill /f /im yourtarget.exe >nul
goto loop

答案 1 :(得分:2)

Python是一个选项:

import subprocess, time

while True:
    proc=subprocess.Popen("something.exe")
    time.sleep(3*60*60) # 3 hours
    proc.kill()
    time.sleep(30)  # 30 seconds

答案 2 :(得分:1)

@set /A _tic=%time:~0,2%*3600^
            +%time:~3,1%*10*60^
            +%time:~4,1%*60^
            +%time:~6,1%*10^
            +%time:~7,1% >nul

:: actual script

@set /A _toc=%time:~0,2%*3600^
            +%time:~3,1%*10*60^
            +%time:~4,1%*60^
            +%time:~6,1%*10^
            +%time:~7,1% >nul


: loop
 @set /A _elapsed=%_toc%-%_tic
 @echo %_elapsed% seconds.
  :: check for elapsed time here

  :: kill the app
  taskkill /im <yourappname>
  :: sleep for some time
  timeout /T 10

  :: start again
  start <yourappname>

goto loop