Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
A string can be executed in the standard java way:
def command = """executable arg1 arg2 arg3"""// 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: ${proc.in.text}" // *out* from the external program is *in* for groovy

{*}Gotchas: * Take care if you wish to pass a quoted argument that contains white space – it will be split into multiple arguments, e.g.:

Code Block

"""executable "first with space" second"""

...

.execute()

will invoke executable with the following arguments:

  • arg1 = "first
  • arg2 = with
  • arg3 = space"
  • arg4 = second

In such a case, you may prefer to use one of the array or list of String variationvariations, e.g.:

Code Block
["executable", "first with space", "second"].execute()

...