You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2017/02/01 23:19:08 UTC

[jira] [Closed] (GROOVY-7150) Redirection of output in javax.script.ScriptEngine.invokeFunction() doesn't work

     [ https://issues.apache.org/jira/browse/GROOVY-7150?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-7150.
-----------------------------

> Redirection of output in javax.script.ScriptEngine.invokeFunction() doesn't work
> --------------------------------------------------------------------------------
>
>                 Key: GROOVY-7150
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7150
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>    Affects Versions: 2.3.6
>         Environment: Java, Windows, Linux
>            Reporter: Shaul Eliyahu
>            Assignee: John Wagenleitner
>             Fix For: 2.4.8
>
>
> The Java code below should return a string "Hello World!". Instead of that it returns an empty string and prints "Hello World!" in the console the application runs. The problem exists only inside functions; texts printed outside functions are redirected properly:
> {code:java}
> javax.script.ScriptEngineManager manager = new ScriptEngineManager();
> javax.script.ScriptEngine engine = manager.getEngineByName("groovy");
> StringWriter stdOut = new StringWriter();
> engine.getContext().setWriter(new PrintWriter(stdOut));
> engine.eval("def myFunction() { print("Hello World!"); }");
> Invocable invoker = (Invocable) engine;
> invoker.invokeFunction("myFunction", new Object[0]);
> return stdOut.getBuffer().toString();
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)