Hi,
I’m trying to execute shell scripts and get back results/outputs using Groovy scripts. The code that I use is
def comm = "/myfilepath/myscript.sh"
def sout = new StringBuffer()
def serr = new StringBuffer()
def var=comm.execute()
var.waitForProcessOutput(sout,serr)
var.consumeProcessOutput(sout,serr)
execution.setVariable("script_op",sout.toString())
Everything works fine, I get the result and I’m able to go ahead with my operations but in the Catalina logs I could see the following error:
Exception in thread “Thread-21992” groovy.lang.GroovyRuntimeException: exception while reading process stream
at org.codehaus.groovy.runtime.ProcessGroovyMethods$TextDumper.run(ProcessGroovyMethods.java:495)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Stream closed
at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:170)
at java.io.BufferedInputStream.read(BufferedInputStream.java:336)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
Exception in thread “Thread-21993” at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.readLine(BufferedReader.java:324)
at java.io.BufferedReader.readLine(BufferedReader.java:389)
at org.codehaus.groovy.runtime.ProcessGroovyMethods$TextDumper.run(ProcessGroovyMethods.java:488)
Any input on how to fix this issue or what is then the right way to execute shell scripts is much appreciated.