Benutzer-Werkzeuge

Webseiten-Werkzeuge


becki:linux:jrunscript

Dies ist eine alte Version des Dokuments!


jrunscipt - Javascript from the Command Line

The jrunscipt command comes with Java 1.6. Use it to call javascript files from the command line. The Rhino scripting engine is used as default.

Usage

jrunscript scriptfile.js arg1 arg2 ...
Using a shebang like !#/usr/lib/java/bin/jrunscript doesn't work so far!

See also the manpage

Built-in global Properties and Functions

Did not find a complete document yet. See Global Properties and Functions, jrunscript JavaScript built-ins (alternaltive)

Note that print and println is somehow not documented in the Built-ins.

Interaction with the underlying OS

Accessing Command Line Arguments

Use the predefined arguments array:

for (var i=0; i<arguments.length; i++) println('Arg '+ i+ ' '+ arguments[i]);

Return exit code

exit(code)

Writing to stdout

echo('Hello world!');
println('Hello World!');
print('Hello World!\n');
printf('Hello World!\n');

Writing to stderr

Did not found a built in function, so i use the java library:

java.lang.System.err.println("Error")

Reading from stdin

FIXME use read

Supporting CLI and HTML Frontend

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
Cookies helfen bei der Bereitstellung von Inhalten. Diese Website verwendet Cookies. Mit der Nutzung der Website erklären Sie sich damit einverstanden, dass Cookies auf Ihrem Computer gespeichert werden. Außerdem bestätigen Sie, dass Sie unsere Datenschutzerklärung gelesen und verstanden haben. Wenn Sie nicht einverstanden sind, verlassen Sie die Website. Weitere Information
becki/linux/jrunscript.1299773659.txt.gz · Zuletzt geändert: 2011-03-10 16:14 von becki

Impressum - Datenschutzerklärung