Get the status using system(command &) when program has been closed

62 views (last 30 days)
Hello guys,
I have another question to ask for today.
I am running an .exe file that takes some time to finish and to output the status. This command runs within app designer and it makes the application unusable (I can click on the stuff but nothing will refresh during system command).
Question: How can I make the App drawnow during the ([ExeFile ' &']) or system (ExeFile)?
Since ExeFile generates another file, I wanted to check if it exists as follows:
system ([ExeFile ' &']); %
while isfile(File_Check) == false
pause (0.5)
But it turns out that file is generated immediately and it increases size as the ExeFile is running, so this does not seem like a good approach.
I also checked the fileattribute for the File_Check and they do not change during the execution. Edit: As stated here it turns out not to be reliable.
Are there any other ways you can think of doing this?
Edit: During the ExeFile run, I get permission denied when I want to delete the file, so, I can just try renaming the file and then rename it back when the command succeeds. But I don't see this as a great idea.

Sign in to comment.

Accepted Answer

Mario Malic
Mario Malic on 26 Aug 2020
Edited: Mario Malic on 26 Aug 2020
Here's an example with simple app.
Process = System.Diagnostics.Process;
% You can check if process is still running
while(Process.HasExited == false)
% do something
If you are running an executable file with input arguments as linked from the answer below (It could be good if mods can accept that answer)
Exe_Process = System.Diagnostics.Process;
Exe_Process.StartInfo.Arguments = '-example arguments';
Exe_Process.StartInfo.FileName = 'C:\program.exe' % full file path
% If you need to execute commands while Exe_Process is running
while Exe_Process.HasExited == false
% do something
pause (0.1) % so MATLAB doesn't check if .exe has stopped silly amount of times
Thanks again for the hint Walter!

Sign in to comment.

More Answers (0)


Find more on Startup and Shutdown in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!