How to exit Nashorn jjs command line tool?

1.2k Views Asked by At

If I start up the Nashorn CLI via jjs, I can't cleanly exit it without using ctrlc.

I tried:

  • exit
  • quit
  • System.exit()

But none worked.

2

There are 2 best solutions below

1
On BEST ANSWER

As per the documentation:

quit()
exit()

These functions are synonymous, causing the current script process to exit to the system.

You can pass an integer value as the argument that represents the exit code to be returned to the system. By default, without an argument, the exit code is set to 0, meaning that the process terminated correctly.

Enter either exit() or quit() to exit the Nashorn shell.

0
On

Simply typing "exit" or "quit" won't work! That will just print toString on those functions (something like "function() { [native code] }"). You need to call those functions like "exit()" or "exit(2)". Also, you need to invoke java.lang.System.exit(int) with fully qualified package name "java.lang" (unlike java where java.lang is always imported!)