How can I have a MCC-compiled application return a specific exit code?

조회 수: 7 (최근 30일)
Daniel
Daniel 2013년 1월 14일
댓글: Oleg Krivosheev 2024년 2월 8일
Hi,
I would like to use a compiled MATLAB application (.exe) as a tool that is called from another application. This is a simple compiled function (single .m file), not an application with GUI. So no callback functions such as yourApp_OutputFcn(hObject, eventdata, handles) are available, I believe.
How can I set the exit code associated with the resulting .exe application inside the MATLAB script, so I can communicate with the calling application using this exit code (e.g., signal success/failure via the exit code)?
Can one of the output parameters of the compiled MATLAB function be used as the exit code? How does mcc set the exit code of the application that it generates?
Thanks for your help, Daniel

답변 (2개)

William Smith
William Smith 2018년 2월 15일
Compiled Matlab programs automatically exit 0 if the main function returns, and -1 if an error occurs prior to this. Maybe that's all you need?
  댓글 수: 2
Bogdan Dzyubak
Bogdan Dzyubak 2021년 8월 5일
If I throw an error, I do get the -1 error code, but it also creates a popup window. Any idea how to avoid this?
Oleg Krivosheev
Oleg Krivosheev 2024년 2월 8일
Well, Windows PowerShell expects return codes to be within [0...256) range. Not sure how -1 will be shown - as 255, I guess?

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2013년 1월 14일
In the output function, for example yourApp_OutputFcn(), set varargout to be the returned values.
% --- Outputs from this function are returned to the command line.
function varargout = yourApp_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
varargout{1} = 42;
Then call your gui. When it exits, it will return whatever you set in varargout{1}.
  댓글 수: 4
Bogdan Dzyubak
Bogdan Dzyubak 2021년 8월 5일
This doesn't appear to work as a true error code. A function like this when compiled on Matlab 2014b and run returns 0 instead of the expected -1:
function error_code = my_function()
try
class
error_code = 0;
catch
error_code = 1;
end
cmd> echo Exit Code is %errorlevel%
0
While the below does give the intended effect, it also creates a popup window. Any suggestions?
function error_code = my_function()
class
Image Analyst
Image Analyst 2021년 8월 5일
@Bogdan Dzyubak, class() is a function that needs you to pass it a variable so it can tell you what kind of variable it is (its class). You did not pass it anything, hence the error about class needing input arguments.
Also, your function never sets anything ever to -1 so I don't know why you expect -1. In fact your function throws an error when it hits the class line so error_code will never be set at all, and that will probably lead to a second error about your function not returning a value.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by