Since you are using bash scripts from the groovy wrapper, stdout and stderr are already redirected to the groovy shell. To override this, you need to use exec inside the shell script.
eg:
groovy script:
def sout = new StringBuffer(), serr = new StringBuffer() def proc ='./script.sh'.execute() proc.consumeProcessOutput(sout, serr) proc.waitForOrKill(1000) println sout
A shell script called script.sh and is located in the same folder:
#!/bin/bash echo "Test redirect"
Running groovy with the shell script above will cause Test redirect to exit to the standard output of the groovy script
Now add the stdout redirect from exec to script.sh`:
#!/bin/bash exec 1>/tmp/test echo "Test redirect"
Now running the groovy script will create the /tmp/test file with the content of Test redirect
You can learn more about I / O redirection in bash here.
source share