How can I force MATLAB 7.9 (R2009b) to wait for an EXE file to complete before continuing with the MATLAB script or function?
11 views (last 30 days)
Show older comments
I call an executable (EXE) file in one of my MATLAB scripts. Now I want MATLAB to wait until the EXE file finishes its task as the code that follows the call requires outputs from the EXE.
Accepted Answer
MathWorks Support Team
on 5 Dec 2012
You can use MATLAB to check if a particular process is running on the system and make MATLAB wait until this process is closed.
Here is a simple example that uses a DOS function SLEEP as the executable. Attached are two files testRun.m and isprocess.m. You will need the isprocess.m file to check the system processes for a particular exe.
testRun shows a sample:
% Do some tasks
% Call sleep.exe for 30 seconds
% (sleep makes dos "idle" for the given time, simulating if the exe were running)
!sleep 30 &
% MATLAB will continue execution once EXE is launched
disp('MATLAB continues after calling EXE')
% Check to see if the EXE process exists
flag = true;
while flag
disp('EXE still running');
flag = isprocess('sleep.exe'); % isprocess is the function attached. Place it on the MATLAB path.
pause(1) % check every 1 second
end
disp('EXE Done')
disp('continuing with MATLAB script')
0 Comments
More Answers (0)
See Also
Categories
Find more on Downloads in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!