如何避免提示当EXE崩溃 [英] How to avoid prompt when EXE crashes

查看:145
本文介绍了如何避免提示当EXE崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行在MATLAB的优化算法,我调用批处理文件(该调用一个EXE文件),在MATLAB每次迭代完成任务。我想这个EXE运行,并在MATLAB中code之前接近继续到下一个迭代。到目前为止,我已经利用了启动/ WAIT在批处理文件中的命令和他们的工作。这是我的例子:

 关闭@echo
@TITLE鸵鸟 - Optimizaton软件工具包REM启动鸵鸟,等到它完成
START / WAIT鸵鸟/ MIN Ostrich.exe回声完成! > OstDone.txt

现在,这里是我的问题。如果Ostrich.exe崩溃,我得到一个提示,要求我进行调试或关闭程序。这意味着我必须present和看屏幕,当我运行该算法(不方便,我在有时慢EXE运行超过1000次迭代)。我有MATLAB code能继续之前关闭程序。

现在,如果我摆脱了/ WAIT部分,添加一个计时器,并做到这一点:

 关闭@echo
@TITLE鸵鸟 - Optimizaton软件工具包REM启动鸵鸟
START鸵鸟/ MIN Ostrich.exeREM间隔2秒
平本地主机-n 2 -w 2500 GT; NULREM如果需要超过2秒,那么它可能已经坠毁。出口:
如果%ERRORLEVEL%NEQ 0退出/ B%ERRORLEVEL%

上面的code引入了新的问题。首先,我估计它需要为EXE每次运行的时间(这是不是时间恒定的量,所以我必须要设置一个上限)和错误检查线是行不通关闭EXE (可能只是关闭该批处理文件,这是不理想的)。

在第二code,如果EXE崩溃则提示出现。然而,MATLAB继续循环和EXE的一个新实例会在新的窗口中运行。如果我获得足够的崩溃,我结束了几个提示在MATLAB循环结束营业。在整体算法的背景下,这是不是一个大问题,但它也并不理想。

基本上,我想code的东西,关闭并重新运行EXE文件,如果它崩溃,或者只是将其关闭(无调试或关闭提示),同时还利用了/ WAIT命令,因为它允许我拿一些快速的EXE运行的优势(EXE的速度取决于我可能会在其输入文件鼓捣很多因素)。

我是新来使用批处理文件和任何帮助将非常AP preciated。


解决方案

 关闭@echo
@TITLE鸵鸟 - 优化软件工具包对/ L %%一中(1,1,1000)做(
REM启动鸵鸟
START鸵鸟/ MIN Ostrich.exeREM间隔2秒
平-N 2本地主机> NUL如果它正在运行或不杀REM鸵鸟,并暂停2秒钟
TASKKILL / F / IMostrich.exe> NUL 2 - ;&放大器; 1
平-N 2本地主机> NUL

I am running an optimization algorithm in MATLAB and I am calling a Batch file (which calls an EXE file) to do a task for each iteration in MATLAB. I want this EXE to run and close before the code in MATLAB continues to the next iteration. So far I have made use of the START /WAIT commands in the Batch file and they work. Here is my example:

@echo off
@TITLE Ostrich - Optimizaton Software Toolkit

REM Launch Ostrich,wait until it completes
START /WAIT "OSTRICH" /MIN Ostrich.exe

echo Done! > OstDone.txt

Now here is my problem. If Ostrich.exe crashes, I get a prompt asking me to debug or close the program. This means I have to be present and watching the screen when I am running this algorithm (not convenient, I am running over 1000 iterations on a sometimes slow EXE). I have to close the program before the MATLAB code can continue.

Now, if I get rid of the /WAIT part, add a timer and do this:

@echo off
@TITLE Ostrich - Optimizaton Software Toolkit

REM Launch Ostrich
START "OSTRICH" /MIN Ostrich.exe

REM Wait 2 seconds
ping localhost -n 2 -w 2500 > nul

REM If it takes more than 2 seconds it has probably crashed. Exit:
if %errorlevel% neq 0 exit /b %errorlevel%

The code above introduces new problems. First, I have to estimate the time it takes for the EXE to run each time (it is not a constant amount of time, so I have to set an upper bound) and the error checking line just doesn't work to close the EXE (probably just closes the batch file which is not ideal).

Under the second code, if the EXE crashes then a prompt comes up. However, the MATLAB loop continues and a new instance of the EXE is run in a new window. If I get enough crashes, I end up with several prompts open at the end of the MATLAB loop. In the context of the overall algorithm, it is not a big deal but it is also not ideal.

Basically, I want to code something that closes and re-runs the EXE file if it crashes, or just closes it (with no debug or close prompt) while still making use of the /WAIT command as it allows me to take advantage of some fast EXE runs (speed of EXE depends on many factors that I may tinker with in its input files).

I am new to using Batch files and any help would be much appreciated.

解决方案

@echo off
@TITLE Ostrich - Optimization Software Toolkit

for /L %%a in (1,1,1000) do (
REM Launch Ostrich
START "OSTRICH" /MIN Ostrich.exe

REM Wait 2 seconds
ping -n 2 localhost>nul

REM kill ostrich if it is running or not, and pause for 2 more seconds
taskkill /f /im "ostrich.exe" >nul 2>&1
ping -n 2 localhost>nul
)

这篇关于如何避免提示当EXE崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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