Time limit for the Exclamation Point — !

I was wondering if anyone knew if there was an established time limit for using the exclamation point to run an external command. I notice an issue that matlab seems to hang if I run an external script that takes too much time. I have searched for a max time so I can put a time limit on my script but I cannot not find a specific listed time.

 채택된 답변

Friedrich
Friedrich 2012년 8월 10일

0 개 추천

Hi,
which OS are you on? On windows you can use activex and the WScript.Shell component to set a timeout and cancel the started process.
% Get interface to Windows Shell objects which allow you to run
% external applications
sh = actxserver('WScript.Shell');
% As an example run cmd.exe
h = sh.Exec('cmd.exe');
% Set timeout on 5 seconds. If timeout is reached terminate the
% application
t = timer('StartDelay',5,'TimerFcn',@(x,y)h.Terminate);
start(t);
% Wait for the application to finish normally or to Timeout
while (strcmp(h.Status,'WshRunning'))
drawnow % Allow timer to execute
end
% Clean-up timer
stop(t);delete(t)
% Get stdout if any
r = h.StdOut.ReadAll

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 8월 10일

0 개 추천

There is no mechanism for imposing time limits in most parts of MATLAB.
(I think I saw discussion in which a way was shown to impose time limits on the Parallel Computing Toolbox "batch" facility. There aren't many other time limits that can be imposed with the cooperation of the code that is executing -- and in your situation you do not have the cooperation of that code.)
Possibly your operating system provides a mechanism for imposing time limits. For example in Unix derived systems, it can be doing using "limit" or "ulimit" commands to set resource limits.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

질문:

2012년 8월 9일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by