Saturday, March 20, 2010

Bash commands from Java: Good way

A string can be executed in the standard java way:
def command = """ping -c1 -W1 hostname""" // Create the String
def proc = command.execute() // Call *execute* on the string
proc.waitFor() // Wait for the command to finish

// Obtain status and output
println "return code: ${ proc.exitValue()}"
println "stderr: ${proc.err.text}"
println "stdout: ${}" // *out* from the external program is *in* for groovy

No comments: