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

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Call Java from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by