簡體   English   中英

如何在腳本末尾關閉 jshell?

[英]How to shutdown jshell at the end of the script?

如何指示jshell在腳本末尾終止,類似於其他語言的解釋器,例如python3node

跟隨命令

./jshell -q /tmp/shell.java

使用腳本/tmp/shell.java

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

印刷

Hello world
jshell> 

並等待進一步的命令。 我希望它在文件末尾立即停止。

我正在尋找比System.exit(0);更優雅的東西。 在腳本的末尾。

在腳本內部,使用jshell命令/exit 這將在腳本結束時退出jshell。

請查看此參考https://docs.oracle.com/javase/9​​/jshell/introduction-jshell.htm#JSHEL-GUID-465BA4F5-E77D-456F-BCB7-D826AC1E18AE

另一種可能性是有一個退出文件:

exit.jsh

/exit

然后運行:

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

另外的選擇:

cat /tmp/shell.java | jshell -

應該在 bash 和 windows powershell 中工作相同

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM