| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
import org.mozilla.javascript.*; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
public class RunScript2 { |
| 15 |
public static void main(String args[]) |
| 16 |
{ |
| 17 |
Context cx = Context.enter(); |
| 18 |
try { |
| 19 |
Scriptable scope = cx.initStandardObjects(); |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
Object jsOut = Context.javaToJS(System.out, scope); |
| 24 |
ScriptableObject.putProperty(scope, "out", jsOut); |
| 25 |
|
| 26 |
String s = ""; |
| 27 |
for (int i=0; i < args.length; i++) { |
| 28 |
s += args[i]; |
| 29 |
} |
| 30 |
Object result = cx.evaluateString(scope, s, "<cmd>", 1, null); |
| 31 |
System.err.println(Context.toString(result)); |
| 32 |
} finally { |
| 33 |
Context.exit(); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
} |
| 38 |
|