我该怎么做 /exit
jshell具有非零错误代码的 session ?
/exit
产量:进程完成,退出代码 0 /exit 1
产量:进程完成,退出代码 0 throw new Error("1")
产量:java.lang.Error throws: 1 at (#24:1)` 和进程完成退出代码 0 System.exit(1)
产量:状态引擎终止。使用以下命令恢复定义:/reload -restore ... 并且 jshell session 不会终止。 像
set -e
这样的 bash 命令不可用。
最佳答案
现在,JShell 附带 JDK 10 后来又推出了新版本的/exit
它将一个可选的片段作为参数。该片段被评估为将返回到调用进程的错误代码。见 http://mail.openjdk.java.net/pipermail/kulla-dev/2017-November/002129.html详情。
这是新 /exit
的帮助文本使用 jdk-10+ea-33 的命令:
| Welcome to JShell -- Version 10
| For an introduction type: /help intro
jshell> /help exit
|
| /exit
|
| Leave the jshell tool. No work is saved.
| Save any work before using this command
|
| /exit
| Leave the jshell tool. The exit status is zero.
|
| /exit <integer-expression-snippet>
| Evaluate the snippet. If the snippet fails or is not an integer expression,
| display the error. Otherwise leave the jshell tool with the
| value of the expression as the exit status
jshell> /exit 123
| Goodbye (123)
备注 JDK 9 : 您不能使用
/exit
退出带有非零错误代码的 JDK 9 上的 jshell session 。见 https://bugs.openjdk.java.net/browse/JDK-8185840详情。
关于java-9 - 使用错误代码退出 jshell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44620232/