1

When I am trying to run a command in UNIX environment using

Runtime.getRuntime().exec("/bin/ksh -c \"ls -al\"")

That works as if the flags were discarded i.e. as if the command line interpreted this as "the first string until space counts". However, running this

Runtime.getRuntime().exec(new String[]{"/bin/ksh", "-c",  "ls -al"});

works as expected... Why??

1 Answer 1

3

Double quoted strings are a shell feature and Runtime.exec() does not invoke a shell to parse the command.

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

2 Comments

Ah.. if I run this command manually from shell, it works fine, but because Runtime is not a shell it does not parse the command the same way?
exactly, it doesn't deal with the double quoted strings, that's the point of the array argument.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.