java - Using Quotes within getRuntime().exec -


i'd invoke bash using string input. like:

sh -l -c "./foo" 

i'd java. unfortunately, when try invoke command using getruntime().exec, following error:

      foo": -c: line 0: unexpected eof while looking matching `"'        foo": -c: line 1: syntax error: unexpected end of file 

it seems related string not being terminated eof.

is there way insert platform specific eof java string? or should looking approach, writing temp script before invoking "sh" ?

use this:

runtime.getruntime().exec(new string[] {"sh", "-l", "-c", "./foo"}); 

main point: don't put double quotes in. that's used when writing command-line in shell!

e.g., echo "hello, world!" (as typed in shell) gets translated to:

runtime.getruntime().exec(new string[] {"echo", "hello, world!"}); 

(just forget moment shell has builtin echo, , calling /bin/echo instead. :-))


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -