I made a small HTTP server using jlink that works when running with the frontend. Now I need to keep a stand-alone math kernel alive after all functions have evaluated for the server to stay up. All functions (including the function to start the server) return immediately, so the behavior of math -script server.m is to exit immediately.

Adding While[True, Pause[1]] to the end of the file causes the server to become unresponsive. $IgnoreEOF=True has no effect (as the documentation says). I experimented briefly with shell tricks (piping to stdin), but did not find a solution -- I'm not a shell expert, and this is on Windows, so solutions are limited to those compatible with PowerShell and SUA.

Similar question to Keep kernel running for execution of scheduled task, but those answers (at least, the While[True...] thing) haven't worked.

  • $\begingroup$ Launch the kernel as a slave from Java. See the sample program here $\endgroup$
    – mfvonh
    Jul 10, 2014 at 18:12
  • $\begingroup$ @mfvonh if you post that as an answer, I'll accept it. I did that and it appears to be the only solution. Thanks. $\endgroup$
    – ZachB
    Jul 23, 2014 at 20:34
  • $\begingroup$ related $\endgroup$ Jul 25, 2014 at 3:34

1 Answer 1


The easiest way to do this is to launch the kernel as a slave from Java. The standard way is to use these args

java ... className -linkmode launch -linkname (* path to kernel *)

And in your class:

KernelLink ml = null;

try {
  ml = MathLinkFactory.createKernelLink(argv);
} catch (MathLinkException e) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.