【问题标题】:Error handling in sets of batch files running in Windows task scheduler在 Windows 任务计划程序中运行的批处理文件集中的错误处理
【发布时间】:2012-03-02 02:11:13
【问题描述】:

假设我有 5 个批处理文件依次运行(通过普通 Windows XP PC 上的 Windows 任务计划程序执行):

Script1.bat
Script2.bat
Script3.bat
Script4.bat
Script5.bat

假设其中一个脚本失败(检测到错误情况——关于如何发生的详细信息对于我的问题并不重要)。如果其他脚本都在任务调度程序中运行,我该如何阻止它们运行?例如,如果 Script1.bat 失败,我不想运行 Script2-5.bat。如果 Script3.bat 失败,我不想运行 Script4-5.bat 等。

我考虑将标志值写入每个脚本将从中读取的临时文件。在每个脚本的开头(第一个除外),它会检查标志是否有效。每次运行这些批处理文件集时,第一个脚本都会在开始时清除此标志。

当然有更好的方法来做到这一点,或者也许有一个标准来处理这种情况?谢谢!

【问题讨论】:

    标签: scheduled-tasks dos


    【解决方案1】:

    编写一个 master.bat 文件,有条件地依次调用每个脚本。然后调度master而不是直接调度5个脚本。

    @echo off
    call Script1.bat
    if %errorlevel%==0 call Script2.bat
    if %errorlevel%==0 call Script3.bat
    if %errorlevel%==0 call Script4.bat
    if %errorlevel%==0 call Script5.bat
    

    【讨论】:

      猜你喜欢
      • 2014-03-15
      • 2014-09-14
      • 2019-04-06
      • 2013-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-19
      • 2015-02-23
      相关资源
      最近更新 更多