Consider that we have the following Groovy script:
temp = a + b
temp * 10
Now, given that a and b are bound to the context with their respective values, and that the script is executed using a groovy shell script.
Is there a way I could obtain the value of thetemp variable assignment, without printing/logging the value to the console? For instance, given a=2 and b=3, I would like to not only know that the script returned 50 but also that temp=5. Is there a way to intercept every assignment to capture the values?
Any suggestions or alternatives are appreciated. Thanks in advance!
You can capture all bindings and assignments from the script by passing a
Bindinginstance to theGroovyShellobject. Consider following example:Running this script prints following two lines to the console:
If you want to access the value of
tempscript variable you simply do: