Frank_Garber
16 years agoNew Contributor
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
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