You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2016/06/29 00:08:10 UTC

[jira] [Commented] (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:comment-tabpanel&focusedCommentId=15353960#comment-15353960 ] 

ASF GitHub Bot commented on GROOVY-7150:
----------------------------------------

Github user asfgit closed the pull request at:

    https://github.com/apache/groovy/pull/230


> 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
>
> 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.4#6332)