Matlab RunTime and argc/argv as input arguments of an app?

I have two apps made on AppDesigner (desktop apps) and, for some reason, I want to generate separate executables files. In this context, I want to call one app from the other using the system command line.
So... I have two questions about it:
(1) Is it possible to open this new app in the same instance of Matlab RunTime (that is running the calling app)?
(2) Is it possible to read command line arguments (like argc and argv in C/C++) as input arguments of a desktop app made on AppDesigner?

4 Comments

Hey @Adam Danz, can you help me with this one? :)
Hello Eric, I've been forgetting to check my mentions and missed your comment. Are you still looking for a solution?
Hi @Adam Danz, I am glad that you are here! :)
(1) Is it possible to open this new app in the same instance of Matlab RunTime (that is running the calling app)?
I still don't know if it is possible.
(2) Is it possible to read command line arguments (like argc and argv in C/C++) as input arguments of a desktop app made on AppDesigner?
I figured out two ways how to deal with it, but both are "bad solutions", I think.
  • Bad solution 1: I edited the list of the input variables of my app and called the app from the prompt, passing the strings (numerical or textual) as arguments. So far so good, BUT the process becomes "stuck" to the prompt, so if I close the prompt this will close my app too.
  • Bad solution 2: I pass the arguments to my app through a file, and its content is read in the startup of my app.
Thanks, but in this case, I may not be that helpful as I've had very limited experience with deployable apps, it's just not my forte. I don't think what you're describing in you Q1 is possible. For your Q2, are you asking how to read the MATLAB-driven command line? diary is often used to read MATLAB command history and this could be an option as it is not listed as an excluded function in compiled apps.

Sign in to comment.

 Accepted Answer

(1) Is it possible to open this new app in the same instance of Matlab RunTime (that is running the calling app)?
I agree, doesn't seem possible for an exe, but MathWorks might know otherwise (this is also not my forte).
(2) Is it possible to read command line arguments (like argc and argv in C/C++) as input arguments of a desktop app made on AppDesigner?
Tested in R2022a
In appdesigner, make a startupFcn callback and right-click on it. You can "Edit App Input Arguments."
My prototype startup function looks like this (and I've added the corresponding Properties "arg1" and "arg2"):
function startupFcn(app, arg1, arg2)
arguments
app
arg1 = 'Hi';
arg2 = 'Ho';
end
app.arg1 = arg1;
app.arg2 = arg2;
end
Setting default values for the arguments allows you to skip them at the command line.
varargin works for this too, but you need somewhere appropriate to stick the arguments. For instance:
function startupFcn(app, varargin)
app.argv = varargin;
end
in the startupFcn, with "argv" as an app property. Simple enough.
Compile the app to a standalone desktop app. In a terminal, you can invoke it with spaces between the arguments:
./appX.exe beep boop
In Matlab, wrap the command with system:
system('./appX.exe beep boop')

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Asked:

on 14 Sep 2022

Edited:

on 9 Nov 2022

Community Treasure Hunt

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

Start Hunting!