Skip to content

Instantly share code, notes, and snippets.

@shalithasuranga
Created January 7, 2019 09:16
Show Gist options
  • Save shalithasuranga/f97cbbc32db045a70a41e4fb3757ba6a to your computer and use it in GitHub Desktop.
Save shalithasuranga/f97cbbc32db045a70a41e4fb3757ba6a to your computer and use it in GitHub Desktop.
package com.mycompany.rhinojsexample;
import com.mycompany.rhinojsexample.hostobjects.ConsoleRunner;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
public class RhinoExample {
public static void main(String[] args) {
String code = "var cr = new ConsoleRunner();"
+ " cr.exec('python --version');";
try {
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
ScriptableObject.defineClass(scope, ConsoleRunner.class);
Object ob = cx.evaluateString(scope, code, "rhinodemojs", 1, null);
System.out.println(Context.toObject(ob, scope));
}
catch(Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment