Sunday 3 July 2016

Run an external command from Groovy and wait for output


// Set up StringBuilders to use for capturing STDOUT and STDERR
def sout = new StringBuilder()
def serr = new StringBuilder()
// Define the command to run
def cmd = "java -jar ~/urbancode/agent/opt/udclient/udclient.jar \
--weburl https://localhost:8443 \
--username admin --password admin getSnapshotsInApplication \
--application Galaxy"

// Run the command
def process = cmd.execute()
// Wait for the process to return and place the resultant STDOUT and STDERR
// into the SringBuilder objects we defined earlier
process.waitForProcessOutput(sout, serr)

// Print STDOUT and STDERR
println sout
println serr

No comments:

Post a Comment