Java Reference
In-Depth Information
Listing 9-1. A jrunscripttest.js Script File Written in Nashorn JavaScript
// jrunscripttest.js
// Print a message
print("Hello Nashorn!");
// Add two integers and print the value
var x = 10;
var y = 20;
var z = x + y;
printf("x + y = z", x, y, z);
The following command runs the script in the jrunscripttest.js file in a batch
mode. You may need to specify the full path of the jrunscripttest.js file if it is not in
the current directory.
C:\>jrunscript -f jrunscripttest.js
Hello Nashorn!
10 + 20 = 30
C:\>
Interactive Mode
In interactive mode, the shell reads and evaluates a script as it is entered on the standard
input. There are two ways to use the shell in interactive mode:
-e or -f options and no arguments
Using no
-f - " option
Using the "
The following command uses no options and arguments to enter into interactive
mode. Pressing the Enter key makes the shell evaluate the entered script. Notice that you
will need to execute the exit() or quit() function to exit from the interactive mode:
c:\>jrunscript
nashorn> print("Hello Interactive mode!");
Hello Interactive mode!
nashorn> var num = 190;
nashorn> print("num is " + num);
num is 190
nashorn> exit();
C:\>
 
Search WWH ::




Custom Search