Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7150

Redirection of output in javax.script.ScriptEngine.invokeFunction() doesn't work

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.6
    • 2.4.8
    • groovy-jdk
    • None
    • Java, Windows, Linux

    Description

      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:

      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();
      

      Attachments

        Issue Links

          Activity

            People

              jwagenleitner John Wagenleitner
              shaule Shaul Eliyahu
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: