0

I cannot figure out what the problem is with the QuercusCompiledScript.eval. Running code:

QuercusScriptEngine quercusScriptEngine = new QuercusScriptEngine();
quercusScriptEngine.eval("<?php echo 'hello uncompiled!\n'; ?>");
CompiledScript script = quercusScriptEngine.compile("<?php echo 'hello compiled!\n'; ?>");
script.eval();
System.out.println("that's all");

produces:

hello uncompiled!
that's all

Debugging this stuff I could not figure out what's wrong, as it does execute the statement, buffers are OK, but the output itself is not performed.

What is wrong?

1 Answers1

0

I found the cause of the problem. The QuercusScriptEngine.eval() explicitly does writer.flush() in the end referring to the http://bugs.caucho.com/view.php?id=1914. But the QuercusCompiledScript.eval() does not, at least in the quercus-4.0.39 (and in the quercus-4.0.45 as well). The workaround is to flush explicitly providing a Writer:

CompiledScript script = quercusScriptEngine.compile("<?php echo 'hello compiled!\n'; ?>");
ScriptContext ctx = quercusScriptEngine.getContext();
Writer writer = new OutputStreamWriter(System.out);
ctx.setWriter(writer);
script.eval(ctx);
writer.flush();