Reputation: 105
Environment: mac
Precondition: I already configured 'adb'
full path to my bash_profile
. and when I tried type 'adb'
in my terminal, it is working.
But, I tried to exec 'adb'
command from java, 'adb'
is not working, instead I need to pass the full adb path to make it work.
I guess this is probably something to do with the bash_profile
setting, anyone know the exact reason for this issue?
Upvotes: 1
Views: 912
Reputation: 15388
Runtime.getRuntime().exec()
runs /bin/sh -c <command>
. If this is or points to a bash shell on your system: A non-interactive bash does not read .bash_profile
unless explicitly (--login
) told to do so.
From the documentation:
When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
It's a little convoluted, but non-interactive, non-login bash instances don't read the profile files.
Your path settings does not get picked up by the subshell (which is actually /bin/sh
which might not even be bash at all).
If you want, you can add the path to adb
system wide by adding an appropriate entry to to /etc/paths.d
.
Upvotes: 1