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

15 ビュー (過去 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.
  1 件のコメント
Jan
Jan 2013 年 2 月 5 日
I do not see how WAITFOR can communicate with the SYSTEM command.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by