简体   繁体   中英

shell_exec doesn't work properly on windows

When I write this script on the command prompt, it works properly :

R CMD BATCH test.R

But, when I'm trying to execute this code in php on windows with :

shell_exec(R CMD BATCH test.R)

It gives me a error : "Error in library(raster) : packages 'raster' was not found"
This has no sense because it does work on unix !

A couple possiblities:

  1. raster package is not installed

  2. PHP PATH when calling shell_exec has different environment variables set so it is not loading the right libs (try setting R_LIBS to fix it).

  3. Try using an absolute path to r instead of a relative one.

for R_LIBS mentioned above: https://stat.ethz.ch/R-manual/R-devel/library/base/html/libPaths.html

By default R_LIBS is unset, and R_LIBS_USER is set to directory 'R/R.version$platform-library/x.y' of the home directory (or 'Library/R/xy/library' for CRAN OS X builds), for R xyz

Example from their FAQ :

"path_to_R\bin\x64\Rgui.exe" HOME=p:/ R_LIBS=p:/myRlib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM