Vinod Jayachandran
Vinod Jayachandran

Reputation: 3898

Invoke script under scripts folder from grails controller

In my Grails application, from controller I am trying to invoke a script present under scripts folder

Controller Code

def invokeScript(){
        def bg= ["groovy","scripts/masterScript.groovy", request.JSON]
        bg.execute();
        render("Script Invoked")
    }

masterScript.groovy

println("Master Script Invoked with arguements " + args[0]);

Expected Output

On Console: "Master Script Invoked with arguements " Response: Script Invoked

Actual Output

No message printed on console but Response is accurate "Script Invoked"

If i invoke the masterScript explicitly from command prompt it works correctly and prints on console.

Please help and clarify the following

  1. Why I don't see any message from script on console when invoked from Controller
  2. Can I set a debug break point in the script present inside Scripts Folder as it is a async call.

Upvotes: 0

Views: 316

Answers (1)

Igor Artamonov
Igor Artamonov

Reputation: 35961

.execute() returns Process instance, that have methods to access output, errors and status code.

So answer for '1': because you don't copy output of a command to your console. See docs: http://www.groovy-lang.org/groovy-dev-kit.html#process-management

And for '2': you cannot, because you're calling script as external process. If you want to evaluate Groovy script, rather than calling plain external command it's better to use GroovyScriptEngine

Upvotes: 1

Related Questions