Java exec can't run program, error = 2

血红的双手。 提交于 2019-12-25 01:12:37

问题


I'm trying to run R.exe from a Java application with Java exec. R is in the Environment Variables and if I execute it from cmd with "R" command it works. If I execute an example instruction in Java and try to open notepad it works:

Runtime rt = Runtime.getRuntime();
Process p = rt.exec("notepad");

But when I try to open R with this instruction:

Process p = rt.exec("R");

it gives me this kind of error:

java.io.IOException: Cannot run program "R": CreateProcess error=2

what could be? why cant I open R from Java?


回答1:


You need to ensure that the Windows PATH includes the directory that R resides in for this to work

CreateProcess error=2 indicates the file can not be found



来源:https://stackoverflow.com/questions/28028684/java-exec-cant-run-program-error-2

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