$PATH variable isn't inherited through getRuntime().exec

假如想象 提交于 2019-11-28 13:57:06
jim
proc = Runtime.getRuntime().exec(cmd, null, fwrkDir);

should be

proc = Runtime.getRuntime().exec(cmd, "PATH=$PATH:/android-sdk-linux_x86/platform-tools", fwrkDir);

Note that the second parameter to the exec() call in your example is null. The second parameter is where you set the environment for the command you are executing. If you are using Java 6, consider using ProcessBuilder.

Found the solution myself. Instead of changing the $PATH variable in .bashsrc, I had to change the $PATH variable in /etc/profile by adding

PATH=$PATH:/android-sdk-linux_x86/platform-tools

Does anyone know why Java needs the global change of the path? Thanks for your answers, though!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!