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

15 次查看(过去 30 天)
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 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by