matlab standalone does NOT exit when run in Windows cmd

11 views (last 30 days)
Hello,
I created a few successfull matlab standalone applications (e.g. plot_data.exe). These applications should read some data, plot, create some mat files. THe code works perfectly in matlab, and the .exe also does what is supposed to do without issues. The problem is that when I run the .exe in Windows cmd (e.g. "C/program/Myexecutable/plot_data.exe"), the program runs correctly, opens all figures but does not exit: a black cmd windows stay open and this window does not close unless I close all the plotted figures.
I have read that A standalone application ends:
when the end of the main function is reached or when there is no visible figure anymore.
However, from my experience it closes only when both the end of the function is reached and also there is no figure visible.
In my case, my intended behaviour is that cmd command can return/exit after the main function in the Matlab .exe is finished (as it always happens when you run a code in Matlab), without waiting for the user to close all figures. In that way I could easily batch things without user interaction required.

Answers (1)

Rik
Rik on 7 Sep 2020
That documentation seems strange to me from a Windows standpoint. Unless you spawn a process by using the batch command start a program will not return control until it is terminated (spawned processes are allowed to survive).
If you want to batch things you will probably have to de-couple computation and visualization (e.g. by running system('start visualize.exe');exit, where visualize is a second compiled function you can use to create the figures), or use start to spawn a new asynchronous process that will run your entire code but will not force cmd to wait until the main execution is done.

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!