I am running under Octave GUI. This command below will shut down Octave GUI regardless what is specified in the preferences for “Confirm before exiting”. I checked the box but Octave window ends once I hit the enter key. I expect to have a choice to remain with or exit from Octave.
javaMethod('exit', 'java.lang.System', 0);
Do you know how to prevent the rapid (forced) closure of the Octave GUI? Thanks.
- Window 10
- Octave 6.3.0 exe installation.
- Java 1.8 SDK/JRE
This is a difficult task for Octave to handle this case, as the whole program execution control is given to Java during
Depending on your Java program, you can try to call it via Octave’s
system-function? Then the Java program termination is a desired action
Thanks for your reply. For my educational purpose, why is shutting down JVM would cause Octave to shut down?
With JavaMethod, I can use a different method within the same class to access the contents of Java run, such as Jframe.
With Jframe.dispose, I can avoid the “crash-alike” behavior of Octave. But, with Jframe.dispose under “system, such as MS DOS”, the app is shut down but JVM is not, and then the (program) control does not return back to system. Jframe.dispose with Octave would meet my need. But Jframe.dispose is not recommended in the Java community for terminating an app.
Philosophically, this is why it is often better to stay within the interpreter rather than venturing out into other execution environments. The same thing can happen with MEX or OCT files. Those latter two are compiled files with direct access to the operating system’s libraries. When Octave executes .mex, .oct, or Java code it gives that code full permissions. If you call
abort (), for example, then that is going to terminate the program immediately regardless of what preferences are set in Octave which apply only to Octave code run within the Octave interpreter.
Just for fun, I tried the Java call in Matlab and it immediately quit too.
Rik, if you take a look at your matlab installation, you should find lots of Java executable jar files. Those jar files are actually used for many things, such plotting, xml reading, pdf, etc. So, shutting down JVM mus be a no-no for matlab. I did find some one published Q/A 10-13 years ago observed the same as what you just tested. But I don’t know why Octave must have jvm up continuously. This is why I posted for help.
I look at 3rd party interface as a very important feature. For example, where can I find an Octave compatible Neural Network package? A text mining package? A fast global optimizer? For many of these type of things, I end up finding what I need in Apache. The associated complication of using 3rd party tools naturally comes into the picture.
There might be some miscommunication here. There are plenty of problems for which Octave is either not the right solution (for example, sysadmin where Perl or shell scripting would be better) or where a good solution already exists and there is no point in porting to Octave when the existing library can be used.
But, whenever you leave the Octave interpreter and start running foreign code there is a potential for problems up to and including immediate hard crashes. It is the price of admission, as it were.
I can’t think of anything that is part of core Octave that needs the JVM except for the ability to execute Java code. Octave does not use Java to provide plotting capabilities (for example). You can certainly start Octave without the JVM if that is what you want.
If you call “exit” in a Java function, you are not calling Octave’s exit function. You exit the entire application, not just the JVM. This is what @rik and @siko1056 are trying to tell you. Calling “exit” in Java will execute a function that exits the entire application immediately. The JVM is loaded in Octave, not executed as a separate process, so “the entire application” is Octave and the JVM executing together in a single process.
Thanks for info. This help request started originally from the system.exit call on the java side: Octave and JVM would terminate at the same time. For easier demonstration, I moved the exit call to Octave function and it did the same.
I read the java document again. The system.exit is said to terminate the threads, JVM and process. If there is only one parent process, all apps should be terminated.
Again, thanks for your help.