Reputation: 3898
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
Upvotes: 0
Views: 316
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