Forum Discussion

Frank_Garber's avatar
Frank_Garber
New Contributor
16 years ago

Groovy script w/ dynamic closure?

Is it possible to dynamically build a string to be used as a closure? Take a look at this contrived example.

Source code:
def commandString = 'println "Hello, world..." + new Date()';
def command = { "${commandString}" };
println "${commandString}"
command();
println 'Done.'

Output:
println "Hello, world..." + new Date()
Done.

The invocation of the command() doesn't produce any output. How can I get the "def command = ..." to actually evaluate the input argument string?

All help is appreciated,

F