0

I have an R script that I need to execute on my PHP page. Here's my code

exec("Rscript D:/webs/popdyn/SingleSpeciesLWR_2.r D:/webs/popdyn/hello.csv none");

I have 2 parameters here, 1st is my csv file and 2nd is none. It works well when I execute this in cmd, but in PHP it doesn't work.

7
  • Give the full path to Rscript. PHP may not find it in its own PATH environment. Commented Nov 19, 2012 at 3:05
  • Do they need to be backslashes to work properly, perhaps? D:\webs\popdyn.... Commented Nov 19, 2012 at 3:05
  • Check permissions and Rscript in PATH Commented Nov 19, 2012 at 3:05
  • Thanks guys, what I did is I gave the full path of Rscript. Commented Nov 19, 2012 at 5:04
  • For some reason, on my local computer it is working fine. And then I tried the same setup with other computer, but php didn't execute the R script. Commented Nov 19, 2012 at 11:35

1 Answer 1

1

This is most likely a PATH issue. Check that Rscript.exe is in the PATH for your system environment, and not your local user environment.

Reason: When PHP runs exec, it run is the environment of the user of the loading application (Could be IIS, Apache or PHP, depending on your set up). You can find out which user and add the path to that user, or just add the path to the system environment. You can do this through the control panel (NOT command line - adds to local only!).

Alternatively, specify the full path to Rscript in the exec().

Sign up to request clarification or add additional context in comments.

1 Comment

For some reason, on my local computer it is working fine. And then I tried the same setup with other computer, but php didn't execute the R script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.