Home > OS >  Waiting for closing of previously started program
Waiting for closing of previously started program

Time:07-15

I would like to ask you how to specify waiting for closing of specific program which was started before. I am showing here an example with command waitfor but unfortunately I don't know how to write it correctly, therefore I am asking you for help.

system('"C:\Program Files\Google\Chrome\Application\chrome.exe" &');
waitfor "closing of chrome.exe"

CodePudding user response:

I guess you can do something like:

time_in_seconds=60
while ~isfile("output_folder/file.db")
   pause(time_in_seconds)
end

Note that this program, as is, requires that file to exist at some point, otherwise infinite loop. Make sure you put safeguards to end it in case the file does not get created (like a time limit).

But I am not sure it makes sense to have MATLAB waiting for 40 minutes for a script to finish...

CodePudding user response:

You should follow the advice in this other Q&A to find the PID of the new program right after you start it. Then, in a loop, check to see if that PID is still running (using again the same process as before), and pause(1) to avoid checking too frequently.

  • Related