Use this:
Runtime.getRuntime().exec(new String[] {"sh", "-l", "-c", "./foo"});
Main point: don't put the double quotes in. That's only used when writing a command-line in the shell!
e.g., echo "Hello, world!"
(as typed in the shell) gets translated to:
Runtime.getRuntime().exec(new String[] {"echo", "Hello, world!"});
(Just forget for the moment that the shell normally has a builtin for echo
, and is calling /bin/echo
instead. :-))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…