Can I force a standlone application to wait until execution is complete?

MATLAB: 2013b, win64
I have compile a very simple tool using MATLAB deploytool and it is being compiled as a standalone executable. The tool is then run from the command line.
My issue is that the command exits immediately and does not wait for the function to finish processing (the tool is creating a file that is needed further down the line).
I know that I can do things on the command line to make execution wait, but my delivery stops at the tool and I would like my delivery to be robust to this issue.
Is there something I can do in the main m-function or as a MATLAB compiler option that will force the resulting executable to wait until all processing is finished?

Answers (1)

Some possibilities include:
  • The executable being built includes functions that cannot be deployed, and the executable exits as soon as it tries to use those functions. For example nothing in the symbolic toolbox an be deployed.
  • The executable uses timers or callbacks to do its work, such as waiting for I/O using callbacks. Executables return as soon as the most immediate function call finishes, which destroys any timer or I/O objects. You need to do something like uiwait() or waitfor() something that indicates that your work is finished. For example there is a timer StopFcn callback that can be used to uiresume()
  • The executable is a GUI that relies on callbacks to do its work. This has the exact same difficulty as above. If you built the GUI using GUIDE, look for the uiwait() that is commented out and remove the comment marker, enabling the uiwait().

4 Comments

I think I may have confused you.
The executable is working perfectly and executes with no issue.
The issue is that the command prompt is not waiting for the executable to finish all of its processing before moving to the next command.
I know that using start /wait will fix this, but that is not a robust solution for me and I'd like to build that functionality into the executable if possible.
If the executable creates a GUI then typically in MS Windows it would effectively fork a new process and disconnect from the parent process (the shell), so as far as system() is concerned, the invoked command is finished.
You could experiment with setting the Target to "Console Application"
Thanks Walter. There is no GUI involved though. I will check the target settings and see if that helps.

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Asked:

on 19 May 2016

Commented:

on 2 Mar 2017

Community Treasure Hunt

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

Start Hunting!