1

When invoking a custom command, I noticed that only the logs are displayed. For example, if my Custom Comand script contains a retrun statement return "great custom command", I can't find it in the result. Both in API Java client or shell execution cases.

What can I do to be able to retrieve that result at the end of an execution?

Thanks.

Command definition in service description file:

    customCommands ([
    "getText" : "getText.groovy"
  ])

getText.groovy file content:

def text = "great custom command"
println "trying to get a text"
return text
Ulky Igor
  • 322
  • 5
  • 16

1 Answers1

1

Assuming that you service file contains the following :

customCommands ([

    "printA" : {
            println "111111"
            return "222222"
    },

    "printB" : "fileB.groovy"
])

And fileB.groovy contains the following code :

println "AAAAAA"

return "BBBBBB"

Then if you run the following command : invoke yourService printA

You will get this :

Invocation results: 1: OK from instance #1..., Result: 222222

invocation completed successfully.

and if you run the following command : invoke yourService printB

You will get this :

Invocation results: 1: OK from instance #1..., Result: AAAAAA

invocation completed successfully.

So if your custom command's implementation is a Groovy closure, then its result is its return value.

And if your custom command's implementation is an external Groovy file, then its result is its last statement output.

HTH,

Tamir.

tamirko
  • 499
  • 5
  • 12
  • Thanks for the answer. `And if your custom command's implementation is an external Groovy file, then its result is its last statement output`When I try it with multiple "println" in the file, all of them appear in the result, and not only the last statement output. In fact, it seems that all logs are displayed as result (because I also have some warning log from gigaspaces logger). – Ulky Igor Sep 18 '14 at 08:09
  • Example of result: **1: OK from instance #1..., Result: /root/gigaspaces/tools/groovy/bin/groovy: 60: [: GNU/Linux: unexpected operator [...]tools/groovy/bin/groovy:[...] CONFIG [com.gigaspaces.logger] - Log file:[...]/logs/2014-09-18~07.56-gigaspaces-service-177.86.0.3-2598.log tomcat-service.groovy(updateWar custom command): warUrl is helloWorld.war... tomcat-service.groovy(updateWar customCommand): invoking updateWarFile custom command tomcat-service.groovy(updateWar customCommand): End invocation completed successfully.** – Ulky Igor Sep 18 '14 at 08:16