1

In reference to the question asked here

How to execute a Groovy Script from my Grails app?

which works except ...how do I pass arguments ?

def cmd = ['groovy.bat', 'C:\\my path\\mysript.groovy']

for a script that is run from the command line like

groovy myscript.groovy -name params.name -project params.name

using CliBuilder for arguments and params from form submitted

Community
  • 1
  • 1
Jabda
  • 1,752
  • 5
  • 26
  • 54

1 Answers1

2

Groovy provides a simple way to execute command line processes. Yo can write the command line as a stringm and call the execute() method. Example:

"groovy myscript.groovy -name nancy -project testproj".execute()

More information in this link.

In case of arguments with whitespaces:

["groovy", 
 "my script with spaces.groovy", 
 "-name", 
 "nancy", 
 "-project", 
 "testproj"].execute()
Miguel Prz
  • 13,718
  • 29
  • 42
  • I have to use a list because there are spaces in my path – Jabda Feb 07 '13 at 20:11
  • for some reason this didn't work initially, before I asked the question.. but it did once I restarted teh grails app. Thanks – Jabda Feb 07 '13 at 21:22