Skip to content

Instantly share code, notes, and snippets.

@alces
Last active August 23, 2016 07:20
Show Gist options
  • Save alces/2f235dd9223b97315b9148bae2c365a8 to your computer and use it in GitHub Desktop.
Save alces/2f235dd9223b97315b9148bae2c365a8 to your computer and use it in GitHub Desktop.
Execute a shell command from Groovy, print its output, and process non-zero exit status
def cmdLine = args.join(' ')
def ps = cmdLine.execute()
ps.in.eachLine {
println it
}
def status = ps.exitValue()
if (status) {
println ps.err.text
throw new IOException("$cmdLine returns $status")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment