Java Reference
In-Depth Information
Using the
jjs
tool, you can run the script in the
stream.js
file as follows. It is
assumed that the
stream.js
file is in the current directory. Otherwise, you need to specify
the full path of the file:
c:\>jjs stream.js
List of numbers: 1,2,3,4,5
Sum of the squares of odd numbers: 35
c:\>jjs stream.js -- 10 11 12 13 14 15
List of numbers: 10,11,12,13,14,15
Sum of the squares of odd numbers: 515
c:\>
Using jjs in Scripting Mode
The
jjs
tool can be invoked in scripting mode, which allows you to run shell commands.
You can start the
jjs
tool in scripting mode using the
-scripting
option. The shell
commands are enclosed in back quotes, not single/double quotes. The following are
examples of using the
date
and
ls
shell commands using the
jjs
tool in scripting mode:
c:\>jjs -scripting
jjs> `date`
Wed Oct 15 15:27:07 CDT 2014
jjs> `ls -l`
total 3102
drwxr-xr-x 4 ksharan Administrators 0 Jan 11 2014 $AVG
drwxr-xr-x 5 ksharan Administrators 0 Jan 22 2014 $Recycle.Bin
-rw-r--r-- 1 ksharan Administrators 1 Jun 18 2013 BOOTNXT
-rw-r--r-- 1 ksharan Administrators 94 May 23 2013 DBAR_Ver.txt
More output goes here...
jjs> exit()
c:\>
Nashorn defines several global objects and functions in scripting mode, as listed
in Table
10-2
.
Search WWH ::
Custom Search