Rhino print function

Greg Pagendam-Turner picture Greg Pagendam-Turner · Sep 13, 2012 · Viewed 17.3k times · Source

I'm using Rhino 1.7R4 and env.js 1.2 to run Javascript code inside Java

I want to print from my Javascript code a string to the Java console.

According to: http://evilroundabout.blogspot.com.au/2009/11/javascript-printing-rhino.html

I should use: print("Hello world");

but when I do I get:

org.mozilla.javascript.EcmaError: ReferenceError: "print" is not defined. (svg-renderer-highcharts-2.1.4.js#20)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3687)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3665)
at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3750)
at org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1794)
at org.mozilla.javascript.ScriptRuntime.getNameFunctionAndThis(ScriptRuntime.java:2188)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1308)
at script.renderSVGFromObject(svg-renderer-highcharts-2.1.4.js:20)

If I use document.write I don't see any output.

Answer

user1545858 picture user1545858 · Sep 13, 2012

I don't think that will work in embedded mode, I think that will only work in the Rhino console.

You can use java.lang.system.out.println. This should work:-

java.lang.System.out.println("HELLO")