如何退出 Nashorn jjs 命令行工具?

How to exit Nashorn jjs command line tool?

如果我通过 jjs 启动 Nashorn CLI,我无法在不使用 ctrlc 的情况下完全退出它.

我试过了:

但是 none 有效。

根据 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.

输入 exit()quit() 退出 Nashorn shell。

简单地输入 "exit" 或 "quit" 是行不通的!这只会在这些函数上打印 toString(类似于 "function() { [native code] }")。您需要像 "exit()" 或 "exit(2)" 这样调用这些函数。此外,您需要使用完全限定的包名称 "java.lang" 调用 java.lang.System.exit(int)(不像 java,其中总是导入 java.lang!)