0

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?

dnsh
  • 3,516
  • 2
  • 22
  • 47

1 Answers1

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

Alan Barrows
  • 579
  • 3
  • 10