Within a Java 1.8 program, how can I execute a program on the user's PATH? For simplicity let's assume that only *nix systems have to be supported. What I want to do is something like:
Runtime.getRuntime().exec("myProgram")
where myProgram is somewhere on the user's PATH.
Runtime.getRuntime().exec(cmd) can only "see" programs on the system's path. For example in my case (mac os) /usr/bin:/bin:/usr/sbin:/sbin, but what if myProgram is in /usr/local/bin or ~/bin?
I tried to get the directories on the user's PATH by parsing the output of Runtime.getRuntime().exec("echo $PATH"), but I get back only the string "$PATH" itself, not the actual content of the PATH variable.
EDIT Executing System.getenv() gives me only PATH=/usr/bin:/bin:/usr/sbin:/sbin, i.e. not the user's PATH.