0
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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Caused by: org.mule.api.config.ConfigurationException: Error creating bean with name 'demo_groovy1Flow1': Cannot create inner bean '(inner bean)' of type [org.mule.module.scripting.component.ScriptComponent] while setting bean property 'messageProcessors' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot create inner bean '(inner bean)' of type [org.mule.module.scripting.component.Scriptable] while setting bean property 'script';
yes, without adding parameter, the code is working fine
then show us the new code. it's hard to guess with such a generic error message
i got the solution. command will not be inside []. But how to pass optional argument. I tried arg* but not working.
0

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

Comments

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.