Forum Discussion

Frank_Garber's avatar
Frank_Garber
New Contributor
17 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

2 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Frank,

    I have no idea :-) Maybe you could try posting this on one of the groovy user lists?

    regards!

    /Ole
    eviware.com