How can I have a MCC-compiled application return a specific exit code?
2 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (2 件)
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
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
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
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
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
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 Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!