Java exec无法运行程序,错误= 2 [英] Java exec can't run program, error = 2

查看:76
本文介绍了Java exec无法运行程序,错误= 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Java exec从Java应用程序运行R.exe.R在环境变量中,如果我使用"R"命令从cmd执行它,它将起作用.如果我使用Java执行示例指令并尝试打开记事本,则它会起作用:

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");

但是当我尝试使用此指令打开R时:

But when I try to open R with this instruction:

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

它给了我这种错误:

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

可能是什么?为什么我不能从Java打开R?

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

推荐答案

您需要确保Windows PATH 包含 R 所在的目录才能正常工作

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

CreateProcess error = 2 表示找不到文件

这篇关于Java exec无法运行程序,错误= 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆