Last active
August 23, 2016 07:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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