简体   繁体   中英

How to run jshell when I don't have a file to execute?

I would like to run jshell like this

$ jshell --execute 'System.out.println("Hello World")'
Hello World
$

So it executes the java single code line and terminates. Is it possible?

You can use a pipe:

echo 'System.out.println("Hello World")' | jshell -

From jshell --help :

A load-file may also be "-" to indicate standard input, without interactive I/O.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM