필터 지우기
필터 지우기

How to make a script wait for a background process to complete before continuing

조회 수: 26 (최근 30일)
Allen Kelly
Allen Kelly 2013년 2월 5일
답변: msand65 2017년 8월 14일
Hey guys, I have a Matlab GUI that requires output from a separate piece of image processing software (ImageJ).
The GUI asks for a file - the file is an LSM file, a specialised image file for use with Zeiss fluorescence imaging microscopes - and uses the system command to tell ImageJ to execute. This takes a few seconds, and currently i'm using a pause command in the code to loop until the last output file from ImageJ is created before commencing.
[pathstr, name, ext] = fileparts(LSMfile);
opt = '-batch';
ProcessLSM = sprintf('%s%s%s%s%s','imagej ',opt,' LSMtoTiff1.ijm "',LSMfile,'"');
system(ProcessLSM);
readNDD2 = 'C:\Temp\NDD2.tif';
readNDD3 = 'C:\Temp\NDD3.tif';
tStamps = 'C:\Temp\Timestamps.txt';
pause on
while exist(tStamps,'file') == 0;
pause(0.1);
end
pause off
While this works, it seems quite cumbersome. Is there any way of having the GUI wait until ImageJ.exe closes in the background before then commencing, instead of using a pause function?
Thanks, Allen

답변 (2개)

msand65
msand65 2017년 8월 14일
Here is what I did for a similar problem: I have a script calling a GUI. The GUI would open and then close without running. So, I assigned a value in the GUI (value_out), had the GUI output to the calling script (function value_out = GUI), and then I put a "waitfor(value_out)" in the calling script after the call to the GUI. There may be some better way to do this (and this may be exactly what Ryan G was implying) but now the script runs and waits for the GUI to be closed before continuing.

Ryan G
Ryan G 2013년 2월 5일
You may be able to implement the waitfor command along with the system command to run the executable. What you would require, however, is something that the executable returns in order to finish the waitfor process.

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by