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

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

2 Comments

I have to use a list because there are spaces in my path
for some reason this didn't work initially, before I asked the question.. but it did once I restarted teh grails app. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.