I'm running a shell command via a system Groovy script. It's a long running process, about 30 minutes, and it is quite verbose. But as written, this waits for the command to complete before printing stdout or stderr. Is there a way to have the output go to the console as the script executes (like it would in a terminal session).
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = "/some/long/running/command".execute()
proc.consumeProcessOutput(sout, serr)
println "STDOUT\n $sout"
println "STDERR\n $serr"
Update: This is the code I'm trying based on the answer. It doesn't print anything until after the process completes, or is killed.
def cmd = "/home/adam/test.sh"
StringBuffer sout = new StringBuffer()
StringBuffer serr = new StringBuffer()
def process = cmd.execute()
process.waitForProcessOutput sout, serr
sout.each
println "Line ${it}"
}