I can use Runtime.exec()
to execute shell commands like \"getprop
\" and \"ls system
\" and they work fine.
However, when I use
@Adi Tiwari, I've found the cause.
Runtime.getRuntime.exec()
doesn't execute a shell command directly, it executes an executable with arguments.
"echo
" is a builtin shell command. It is actually a part of the argument of the executable sh
with the option -c
.
Commands like ls
are actual executables.
You can use type echo
and type ls
command in adb shell
to see the difference.
So final code is:
String[] cmdline = { "sh", "-c", "echo $BOOTCLASSPATH" };
Runtime.getRuntime().exec(cmdline);