title: How to redirect output from Groovy script?
body: <p>I wonder if there is any way I could change the default output (System.out) for the groovy script that I'm executing from my Java code.</p>
  
  <p>Here is the Java code:</p>
  
  <pre><code>public void exec(File file, OutputStream output) throws Exception {
      GroovyShell shell = new GroovyShell();
      shell.evaluate(file);
  }
  </code></pre>
  
  <p>And the sample groovy script:</p>
  
  <pre><code>def name='World'
  println "Hello $name!"
  </code></pre>
  
  <p>Currently the execution of the method, evaluates scripts that writes "Hello World!" to the console (System.out). How can I redirect output to the OutputStream passed as a parameter?</p>