1

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?

1 Answer 1

3

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.

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

1 Comment

This worked! I'm a big fan of that syntax for the control you get of each parameter

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.