在批处理文件中使用ERRORLEVEL知道,如果一个程序正常退出 [英] using errorlevel in a batch file to know if a program exited normally

查看:352
本文介绍了在批处理文件中使用ERRORLEVEL知道,如果一个程序正常退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个程序,偶尔会崩溃。客户从运行计划任务程序。当程序以一定参数运行,该程序运行作为一个接口引擎,创建一个文件,然后由另一程序的文件ftp'ing到另一个服务器进行导入。

我在想,如果我可能有计划的任务,而不是运行的批处理文件。该批处理文件将运行程序并检查错误级别作为程序退出。如果错误级别不等于零,则批处理文件将再次运行程序。有谁看问题,我计划在批处理文件中使用错误级别

下面是批处理文件的例子:

 :启动
myPgm.exe INTFC
如果错误级别<> 0再启动


解决方案

我会写它就像这样:

 :启动
myPgm.exe INTFC
IF%ERRORLEVEL%NEQ 0 GOTO:错误
GOTO:结束
:错误
回声时出错。
1号出口
:结束
回声结束。
EXIT 0

We have a program that is occasionally crashing. The customer runs the program from a scheduled task. When the program is run with a certain parameter, the program runs as an interface engine, creating a file and then ftp'ing the file to another server for import by another program.

I was wondering if I might have the scheduled task instead run a batch file. The batch file would run the program and check errorlevel as the program exits. If errorlevel is not equal to zero, then batch file would run the program again. Does anyone see problem with my plan to use errorlevel in a batch file?

Here's an example of the batch file:

:start    
myPgm.exe intfc    
if errorlevel <> 0 then start

解决方案

I would write it like so:

:start
myPgm.exe intfc
IF %errorlevel% NEQ 0 GOTO :error
GOTO :end
:error
echo There was an error.
EXIT 1
:end
echo End.
EXIT 0

这篇关于在批处理文件中使用ERRORLEVEL知道,如果一个程序正常退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆