# Keep batch-mode kernel alive

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.

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

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 *)


KernelLink ml = null;