Nick Grealy Nick Grealy - 1 month ago 8
Groovy Question

Groovy > Where is the documentation for execute(..) with parameters?

Where is the documentation for the

execute(..)
method with parameters?

I can't find any official documentation. (N.B. I'm not looking to use ProcessBuilder).

Here is the example usage:

def sb = new StringBuilder()
def proc = ['cmd','/c','echo %AAA%'].execute(["AAA=XXX", "BBB=YYY"], null)
// def proc = ['/bin/bash','-c','echo $AAA'].execute(["AAA=XXX", , "BBB=YYY"], null)
proc.consumeProcessOutput(sb, sb)
proc.waitForOrKill(5000)
println sb.toString() // -> XXX


This nabble post, alludes to being able to pass a String array of
key=value
pairs...

ENV = [:]
ENV.MYVAR = 'Foo Bar'
ENV.X = 'Baz'

String[] ENVtoArray() { ENV.collect { k, v -> "$k=$v" } }

ENVtoArray()
==>
{"MYVAR=Foo Bar", "X=Baz"}

"bash -c set".execute(ENVtoArray(), null).text
==>


GroovyVersion: 2.4.5

UPDATE**:



Got previous example working, by adding the
cmd /c
. Changing question to "Where is the documentation for the
execute(..)
method (with parameters).