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

20 Ansichten (letzte 30 Tage)
Eric Delgado
Eric Delgado am 14 Sep. 2022
Bearbeitet: Chris am 9 Nov. 2022
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 Kommentare
Eric Delgado
Eric Delgado am 6 Okt. 2022
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.
Adam Danz
Adam Danz am 6 Okt. 2022
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Chris
Chris am 9 Nov. 2022
Bearbeitet: Chris am 9 Nov. 2022
(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')

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Runtime finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by