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
Post a Comment