зеркало из https://github.com/mozilla/pjs.git
Documentation about runCommand in shell
This commit is contained in:
Родитель
1e2468a7fc
Коммит
1e22de7bf6
|
@ -7,9 +7,9 @@
|
||||||
<body bgcolor="#ffffff">
|
<body bgcolor="#ffffff">
|
||||||
|
|
||||||
<h1 align="center">
|
<h1 align="center">
|
||||||
Change Log for Significant Rhino Changes</h1>
|
Rhino Change Log</h1>
|
||||||
|
|
||||||
This is a log of significant changes since the release of Rhino 1.5 Release 3.
|
This is a log of changes since the release of Rhino 1.5 Release 3.
|
||||||
|
|
||||||
<h3>Rhino debug API changes</h3>
|
<h3>Rhino debug API changes</h3>
|
||||||
|
|
||||||
|
@ -52,6 +52,9 @@ var obj = new fooJar.Foo(1, 2, 3);
|
||||||
obj.someMethod();
|
obj.someMethod();
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
<h3>Shell function to run external processes.</h3>
|
||||||
|
A new <tt>runCommand</tt> function is added to <a href="shell.html">Rhino Shell</a> to run external priocesses. For details, see JavaDoc for <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/Global.java">org.mozilla.javascript.tools.shell.Global#runCommand</a>.</blockquote>
|
||||||
|
|
||||||
<h3>Resolved Bugzilla reports</h3>
|
<h3>Resolved Bugzilla reports</h3>
|
||||||
|
|
||||||
The following Rhino reports in <a href="http://bugzilla.mozilla.org/">Bugzilla</a> where resolved for Rhino 1.5 Release 4.
|
The following Rhino reports in <a href="http://bugzilla.mozilla.org/">Bugzilla</a> where resolved for Rhino 1.5 Release 4.
|
||||||
|
|
|
@ -57,6 +57,11 @@ defineClass(<i>className</i>)</h4>
|
||||||
argument <i>className</i>. Uses ScriptableObject.defineClass() to define
|
argument <i>className</i>. Uses ScriptableObject.defineClass() to define
|
||||||
the extension.</blockquote>
|
the extension.</blockquote>
|
||||||
|
|
||||||
|
<h4>
|
||||||
|
deserialize(<i>filename</i>)</h4>
|
||||||
|
|
||||||
|
<blockquote>Restore from the specified file an object previously written by a call to <tt>serialize</tt>.</blockquote>
|
||||||
|
|
||||||
<h4>
|
<h4>
|
||||||
load([<i>filename</i>, ...])</h4>
|
load([<i>filename</i>, ...])</h4>
|
||||||
|
|
||||||
|
@ -76,6 +81,26 @@ print([<i>expr</i> ...])</h4>
|
||||||
<blockquote>Evaluate and print expressions. Evaluates each expression,
|
<blockquote>Evaluate and print expressions. Evaluates each expression,
|
||||||
converts the result to a string, and prints it.</blockquote>
|
converts the result to a string, and prints it.</blockquote>
|
||||||
|
|
||||||
|
<h4>
|
||||||
|
runCommand(<i>commandName</i>, [<i>arg</i>, ...] [<i>options</i>])</h4>
|
||||||
|
|
||||||
|
<blockquote>Execute the specified command with the given argument and options
|
||||||
|
as a separate process and return the exit status of the process. For details, see JavaDoc for <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/Global.java">org.mozilla.javascript.tools.shell.Global#runCommand</a>.</blockquote>
|
||||||
|
|
||||||
|
<h4>
|
||||||
|
serialize(<i>object</i>, <i>filename</i>)</h4>
|
||||||
|
<blockquote>Serialize the given object to the specified file.</blockquote>
|
||||||
|
|
||||||
|
<h4>
|
||||||
|
spawn(<i>functionOrScript</i>)</h4>
|
||||||
|
|
||||||
|
<blockquote>Run the given function or script in a different thread.</blockquote>
|
||||||
|
|
||||||
|
<h4>
|
||||||
|
sync(<i>function</i>)</h4>
|
||||||
|
|
||||||
|
<blockquote>creates a synchronized function (in the sense of a Java synchronized method) from an existing function. The new function synchronizes on the <code>this</code> object of its invocation.</blockquote>
|
||||||
|
|
||||||
<h4>
|
<h4>
|
||||||
quit()</h4>
|
quit()</h4>
|
||||||
|
|
||||||
|
@ -93,35 +118,103 @@ respectively.</blockquote>
|
||||||
|
|
||||||
<h2>
|
<h2>
|
||||||
Example</h2>
|
Example</h2>
|
||||||
|
|
||||||
|
<h4>Invocation</h4>
|
||||||
Here the shell is invoked three times from the command line. (The system
|
Here the shell is invoked three times from the command line. (The system
|
||||||
command prompt is shown as <tt>$</tt>.) The first invocation executes a
|
command prompt is shown as <tt>$</tt>.) The first invocation executes a
|
||||||
script specified on the command line itself. The next invocation has no
|
script specified on the command line itself. The next invocation has no
|
||||||
arguments, so the shell goes into interactive mode, reading and evaluating
|
arguments, so the shell goes into interactive mode, reading and evaluating
|
||||||
each line as it is typed in. Finally, the last invocation executes a script
|
each line as it is typed in. Finally, the last invocation executes a script
|
||||||
from a file and accesses arguments to the script itself.
|
from a file and accesses arguments to the script itself.
|
||||||
<p><tt>$ java org.mozilla.javascript.tools.shell.Main -e print('hi')</tt>
|
<pre>
|
||||||
<p><tt>hi</tt>
|
$ java org.mozilla.javascript.tools.shell.Main -e print('hi')
|
||||||
<p><tt>$ java org.mozilla.javascript.tools.shell.Main</tt>
|
hi
|
||||||
<p><tt>js> print('hi')</tt>
|
$ java org.mozilla.javascript.tools.shell.Main
|
||||||
<br><tt>hi</tt>
|
js> print('hi')
|
||||||
<br><tt>js> 6*7</tt>
|
hi
|
||||||
<br><tt>42</tt>
|
js> 6*7
|
||||||
<br><tt>js> function f() {</tt>
|
42
|
||||||
<br><tt> return a;</tt>
|
js> function f() {
|
||||||
<br><tt>}</tt>
|
return a;
|
||||||
<br><tt>js> var a = 34;</tt>
|
}
|
||||||
<br><tt>js> f()</tt>
|
js> var a = 34;
|
||||||
<br><tt>34</tt>
|
js> f()
|
||||||
<br><tt>js> quit()</tt>
|
34
|
||||||
<p><tt>$ cat echo.js</tt>
|
js> quit()
|
||||||
<br><tt>for (i in arguments) {</tt>
|
$ cat echo.js
|
||||||
<br><tt> print(arguments[i])</tt>
|
for (i in arguments) {
|
||||||
<br><tt>}</tt>
|
print(arguments[i])
|
||||||
<br><tt>$ java org.mozilla.javascript.tools.shell.Main echo.js foo bar</tt>
|
}
|
||||||
<p><tt>foo</tt>
|
$ java org.mozilla.javascript.tools.shell.Main echo.js foo bar
|
||||||
<br><tt>bar</tt>
|
foo
|
||||||
<p><tt>$</tt>
|
bar
|
||||||
<p>
|
$
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<h4>spawn and sync</h4>
|
||||||
|
The following example creates 2 threads via <tt>spawn</tt> and uses <tt>sync</tt> to create a synchronized version of the function <tt>test</tt>.
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
js> function test(x) {
|
||||||
|
print("entry");
|
||||||
|
java.lang.Thread.sleep(x*1000);
|
||||||
|
print("exit");
|
||||||
|
}
|
||||||
|
js> var o = { f : sync(test) };
|
||||||
|
js> spawn(function() {o.f(5);});
|
||||||
|
Thread[Thread-0,5,main]
|
||||||
|
entry
|
||||||
|
js> spawn(function() {o.f(5);});
|
||||||
|
Thread[Thread-1,5,main]
|
||||||
|
js>
|
||||||
|
exit
|
||||||
|
entry
|
||||||
|
exit
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<h4>runCommand</h4>
|
||||||
|
Here is few examples of invoking <tt>runCommand</tt> under Linux.
|
||||||
|
<pre>
|
||||||
|
js> runCommand('date')
|
||||||
|
Thu Jan 23 16:49:36 CET 2003
|
||||||
|
0
|
||||||
|
// Using input option to provide process input
|
||||||
|
js> runCommand("sort", {input: "c\na\nb"})
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
0
|
||||||
|
js> // Demo of output and err options
|
||||||
|
js> var opt={input: "c\na\nb", output: 'Sort Output:\n'}
|
||||||
|
js> runCommand("sort", opt)
|
||||||
|
0
|
||||||
|
js> print(opt.output)
|
||||||
|
Sort Output:
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
js> var opt={input: "c\na\nb", output: 'Sort Output:\n', err: ''}
|
||||||
|
js> runCommand("sort", "--bad-arg", opt)
|
||||||
|
2
|
||||||
|
js> print(opt.err)
|
||||||
|
/bin/sort: unrecognized option `--bad-arg'
|
||||||
|
Try `/bin/sort --help' for more information.
|
||||||
|
|
||||||
|
js> runCommand("bad_command", "--bad-arg", opt)
|
||||||
|
js: "<stdin>", line 18: uncaught JavaScript exception: java.io.IOException: bad_command: not found
|
||||||
|
js> // Passing explicit environment to the system shell
|
||||||
|
js> runCommand("sh", "-c", "echo $env1 $env2", { env: {env1: 100, env2: 200}})
|
||||||
|
100 200
|
||||||
|
0
|
||||||
|
js> // Use args option to provide additional command arguments
|
||||||
|
js> var arg_array = [1, 2, 3, 4];
|
||||||
|
js> runCommand("echo", { args: arg_array})
|
||||||
|
1 2 3 4
|
||||||
|
0
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<hr WIDTH="100%">
|
<hr WIDTH="100%">
|
||||||
<br><a href="index.html">back to top</a>
|
<br><a href="index.html">back to top</a>
|
||||||
</body>
|
</body>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче