How to make a script wait for a background process to complete before continuing
14 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
msand65
on 14 Aug 2017
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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!