Error equivalent for process.text?

You can get the whole output stream using .text:

def process = "ls -l".execute()
println "Found text ${process.text}"

Is there a brief equivalent to getting a stream of errors?

+5
source share
2 answers

You can use waitForProcessOutputone that accepts two appendables ( docs here )

def process = "ls -l".execute()
def (output, error) = new StringWriter().with { o -> // For the output
  new StringWriter().with { e ->                     // For the error stream
    process.waitForProcessOutput( o, e )
    [ o, e ]*.toString()                             // Return them both
  }
}
// And print them out...
println "OUT: $output"
println "ERR: $error"
+7
source

Based on tim_yates answer I tried this on Jenkins and found this problem with several assignments: https://issues.jenkins-ci.org/browse/JENKINS-45575

So this works, and it is also concise:

def process = "ls -l".execute()
def output = new StringWriter(), error = new StringWriter()
process.waitForProcessOutput(output, error)
println "exit value=${process.exitValue()}"
println "OUT: $output"
println "ERR: $error"
0
source

All Articles