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

2 Ansichten (letzte 30 Tage)
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 Kommentar
Adithya Addanki
Adithya Addanki am 29 Feb. 2016
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

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Call Java from MATLAB 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