swinters
swinters

Reputation: 347

Calling Bash script from Java changing arguments

Directly from terminal, I can call sh script.sh "test ing" 1 2 works fine -- there are 3 arguments: test ing, 1, 2

Calling the exact same thing from java with Process call = Runtime.getRuntime().exec("sh script.sh \"test ing\" 1 2") has 4 arguments: "test, ing", 1, 2

To clarify, I can remove the quotes and calling the both cases have the same behavior as calling from java. How can I call this script from java to work with my desired behavior of its arguments?

Upvotes: 1

Views: 51

Answers (1)

mauriciojost
mauriciojost

Reputation: 370

You could also try with:

Process call = Runtime.getRuntime().exec(new String[]{"sh", "script.sh", "test ing", "1", "2"});

This way allows you to have more control on the arguments you pass.

Upvotes: 3

Related Questions