user3663479
user3663479

Reputation: 11

How to pass parameter while executing command in Groovy Script

command = ["C:/Users/Desktop/try.bat"] 
def command1=command    
def cmd = command1.execute()    
cmd.waitFor()

This is my code. But I need to pass 4 arguments to try.bat. Out of these one argument is optional. How to handle it?

Upvotes: 0

Views: 2705

Answers (2)

Kasper Ziemianek
Kasper Ziemianek

Reputation: 1349

Maybe you should try

def command = """C:/Users/Desktop/try.bat arg1 arg2 arg3 arg4"""

as the official docs provided suggest http://groovy.codehaus.org/Executing+External+Processes+From+Groovy

Upvotes: 0

cfrick
cfrick

Reputation: 37008

add more items in the array

["command", "param1", "param2"].execute()

as stated in the official docs http://groovy.codehaus.org/Executing+External+Processes+From+Groovy

Upvotes: 1

Related Questions