Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
|
becki:linux:jrunscript [2010-08-16 12:06] becki created |
becki:linux:jrunscript [2011-03-22 13:55] (aktuell) becki |
||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== jrunscipt - Javascript from the Command Line == | + | ====== Standalone Javascript == |
| - | 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. | + | This page is about [[http://www.mozilla.org/rhino/|Rhino]], the scripting engine that comes with Java 1.6. |
| - | ===== Usage == | + | ===== Basic Usage == |
| jrunscript scriptfile.js arg1 arg2 ... | jrunscript scriptfile.js arg1 arg2 ... | ||
| <note important>Using a shebang like ''!#/usr/lib/java/bin/jrunscript'' doesn't work so far!</note> | <note important>Using a shebang like ''!#/usr/lib/java/bin/jrunscript'' doesn't work so far!</note> | ||
| + | |||
| + | ''jrunscript -q'' reveals the version of Rhino. | ||
| See also the [[http://download.oracle.com/javase/6/docs/technotes/tools/share/jrunscript.html|manpage]] | See also the [[http://download.oracle.com/javase/6/docs/technotes/tools/share/jrunscript.html|manpage]] | ||
| Zeile 13: | Zeile 15: | ||
| ===== Built-in global Properties and Functions == | ===== Built-in global Properties and Functions == | ||
| - | Did not find a complete document yet. See [[http://www.herongyang.com/JavaScript/Built-In-Object-Global-Properties-and-Functions-jrunscript.html|Global Properties and Functions]], [[http://download.oracle.com/javase/7/docs/technotes/tools/share/jsdocs/GLOBALS.html|jrunscript JavaScript built-ins]] ([[http://www.silab.dsi.unimi.it/manual/JDK%206%20Documentation/technotes/tools/share/jsdocs/index.html|alternaltive]]) | + | Did not find a complete document yet. The [[http://www.silab.dsi.unimi.it/manual/JDK%206%20Documentation/technotes/tools/share/jsdocs/index.html|jrunscript JavaScript built-ins]] ([[http://download.oracle.com/javase/7/docs/technotes/tools/share/jsdocs/GLOBALS.html|alternaltive]]) are not complete (e.g. print() / println() are missing). The functions listed in [[https://developer.mozilla.org/en/Rhino_Shell|Rhino Shell]] are obviously not in sync with jrunsricpt (e.g. ''readFile()'' is not available). |
| - | Note that ''print'' and ''println'' is somehow not documented in the Built-ins. | + | 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: [[http://www.herongyang.com/JavaScript/Built-In-Object-Global-Properties-and-Functions-jrunscript.html|Global Properties and Functions]]. Here is a shortcut: |
| + | |||
| + | jrunscript -e 'for (i in this) echo("/** "+i+" */", this[i])' | ||
| ===== Interaction with the underlying OS == | ===== Interaction with the underlying OS == | ||
| Zeile 25: | Zeile 29: | ||
| for (var i=0; i<arguments.length; i++) println('Arg '+ i+ ' '+ arguments[i]); | for (var i=0; i<arguments.length; i++) println('Arg '+ i+ ' '+ arguments[i]); | ||
| </code> | </code> | ||
| + | |||
| + | ==== Return exit code == | ||
| + | |||
| + | exit(code) | ||
| ==== Writing to stdout == | ==== Writing to stdout == | ||
| Zeile 37: | Zeile 45: | ||
| ==== Writing to stderr == | ==== Writing to stderr == | ||
| - | FIXME | + | Did not found a built in function, so i use the java library: |
| + | |||
| + | <code javascript> | ||
| + | java.lang.System.err.println("Error") | ||
| + | </code> | ||
| ==== Reading from stdin == | ==== Reading from stdin == | ||
| Zeile 52: | Zeile 65: | ||
| |--- core_app.js | |--- core_app.js | ||
| html_dom.js <---´ | html_dom.js <---´ | ||
| + | |||
| + | <code javascript> | ||
| + | load('core_app.js') | ||
| + | core_app() // function is defined in core_app.js | ||
| + | </code> | ||