How to exit process with exit code from a MATLAB's compiled java jar on Linux?

2 ビュー (過去 30 日間)
Shaked Dovrat
Shaked Dovrat 2016 年 2 月 25 日
コメント済み: Adithya Addanki 2016 年 2 月 29 日
I want to exit from a MATLAB's compiled java jar on a Unix (Linux) system, with an error code (zero for success, one for failure).
Normally I would use
exit(exit_code);
But in the compiled java jar I get an error in the format of a segmentation fault (segfault) error, only it says std:terminate() detected. I've created a dummy function to test the behavior:
function num = temp_jar(string)
num = str2double(string);
if isnan(num)
error('Can''t convert argument "%s" to number', num);
end
if num >= 0
fprintf('exit(%g)', num);
exit(num)
else
fprintf('exit (without params)');
exit
end
end
The segfault-like error happens in every type of call to exit on the compiled temp_jar function.
Is there a way to properly exit (with an error code) from a compiled java jar file on MATLAB?
If not, are there any workarounds?
  1 件のコメント
Adithya Addanki
Adithya Addanki 2016 年 2 月 29 日
Hi Shaked Dovrat,
Please note that calling "exit" kills the process, thus shutting down the MATLAB environment. Here MATLAB is not in control of the process, but JVM is, so it is interpreting this shutdown as a crash.
Theoretically, if you need to retrieve this exit code, you may write a terminate signal handler in Java. This Java application may need to catch the shutdown signal and treat it differently instead of just crashing.
Thank you,
Adithya

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeCall Java from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by