How to shutdown jshell at the end of the script?

六月ゝ 毕业季﹏ 提交于 2019-12-03 10:34:36

问题


How to instruct jshell to terminate at the end of the script similarly to interpreters of other languages like for example python3 or node?

Following command

./jshell -q /tmp/shell.java

with script /tmp/shell.java

System.out.println("Hello world");

prints

Hello world
jshell> 

and waits for further commands. I'd like it to stop immediately at the end of the file.

I'm looking for something more elegant than System.exit(0); at the end of the script.


回答1:


Inside the script, use the jshell command /exit. This will exit jshell at the end of your script.

Check this reference https://docs.oracle.com/javase/9/jshell/introduction-jshell.htm#JSHEL-GUID-465BA4F5-E77D-456F-BCB7-D826AC1E18AE




回答2:


Another possibility is to have an exit file:

exit.jsh

/exit

And then run:

./jshell --startup myscript.jsh --startup exit.jsh


来源:https://stackoverflow.com/questions/43377787/how-to-shutdown-jshell-at-the-end-of-the-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!