This page is about Rhino, the scripting engine that comes with Java 1.6.
jrunscript scriptfile.js arg1 arg2 ...
!#/usr/lib/java/bin/jrunscript
doesn't work so far!
jrunscript -q
reveals the version of Rhino.
See also the manpage
Did not find a complete document yet. The jrunscript JavaScript built-ins (alternaltive) are not complete (e.g. print() / println() are missing). The functions listed in Rhino Shell are obviously not in sync with jrunsricpt (e.g. readFile()
is not available).
The IMHO only way to really find out which functions you have is to have a script print out the functions. This is described here: Global Properties and Functions. Here is a shortcut:
jrunscript -e 'for (i in this) echo("/** "+i+" */", this[i])'
Use the predefined arguments
array:
for (var i=0; i<arguments.length; i++) println('Arg '+ i+ ' '+ arguments[i]);
exit(code)
echo('Hello world!'); println('Hello World!'); print('Hello World!\n'); printf('Hello World!\n');
Did not found a built in function, so i use the java library:
java.lang.System.err.println("Error")
use read
From within a Webbrowser, you have access to the DOM API whereas from jrunscript (with Rhino) you have access to the jrunscript Built-ins and the Java-API. The only intersection are the javascript built in core functions and objects.
In order to support both a CLI- and a Web frontend one should separate the frontend-specific code from the generic application code:
cli.js <---. |--- core_app.js html_dom.js <---´
load('core_app.js') core_app() // function is defined in core_app.js