Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

rhino shell run scripts in batch mode

36 views
Skip to first unread message

peggy

unread,
Nov 18, 2009, 9:49:09 PM11/18/09
to
hihi,

i use bash shell to call js using rhino.

ex:
java -jar ../path/to/js.jar ex1.js $*
java -jar ../path/to/js.jar ex2.js $*
java -jar ../path/to/js.jar ex3.js $*


ex1,ex2,ex3 are different javacript project and excute easy script(
like as only print for test). must it write many times [java -jar
../path/to/js.jar ] ? it is very slowly to start java to excute ex1(2,3).js
everytime.
coz it will let %cpu high to start java everytime.

thanks.
peggy.


Cameron McCormack

unread,
Nov 18, 2009, 10:02:14 PM11/18/09
to
Hi Peggy.

The JS shell can evaluate multiple files:

$ java -jar js.jar -help
Usage: java org.mozilla.javascript.tools.shell.Main [options...] [files]
Valid options are:
-?, -help Displays help messages.
-w Enable warnings.
-version 100|110|120|130|140|150|160|170
Set a specific language version.
-opt [-1|0-9] Set optimization level.
-f script-filename Execute script file, or "-" for interactive.
-e script-source Evaluate inline script.
-debug Generate debug code.
-strict Enable strict mode warnings.
-fatal-warnings Treat warnings as errors.
-encoding charset Use specified character encoding as default when
reading scripts.
$ cat a.js
print("hello")
$ cat b.js
print("there")
$ java -jar js.jar -f a.js -f b.js
hello
there

Although the usage information says "[files]" at the end, it seems you
can only list a single file (if you don't use the "-f" option like above).

peggy

unread,
Nov 19, 2009, 12:09:21 AM11/19/09
to
hi, Cameron McCormack

thanks for replay!

coz i have arguments with the javascript file, like as ex1.js
arg1(ex2.js arg2), how can i cat those js files.

thanks.


"Cameron McCormack" <c...@mcc.id.au> wrote in message
news:z-2dnR5-yLSlKJnW...@mozilla.org...

peggy

unread,
Nov 19, 2009, 12:14:54 AM11/19/09
to
hi, Cameron McCormack

i do this thing below:

$cat ex1.js ex2.js > ex.js
$java -jar ../path/to/js.jar ex.js

but i must have arguments in every js. how can i do

thanks

"Cameron McCormack" <c...@mcc.id.au> wrote in message
news:z-2dnR5-yLSlKJnW...@mozilla.org...

Cameron McCormack

unread,
Nov 19, 2009, 12:23:26 AM11/19/09
to
peggy wrote:
> coz i have arguments with the javascript file, like as ex1.js
> arg1(ex2.js arg2), how can i cat those js files.

The shell can only take a single list of arguments to pass to all of the
scripts it runs. You will need to either change your scripts so that
they can all work off the same 'arguments' array or write your own small
Java program that loads the script files and passes the relevant list of
arguments to each of the scripts.

peggy

unread,
Nov 19, 2009, 12:43:17 AM11/19/09
to
hi, Cameron

very thanks for ur answer!!

peggy


"Cameron McCormack" <c...@mcc.id.au> wrote in message

news:JYydnYkXj7XSS5nW...@mozilla.org...

0 new messages