shell_exec 在 windows 上无法正常工作
shell_exec doesn't work properly on windows
当我在命令提示符下编写这个脚本时,它工作正常:
R CMD BATCH test.R
但是,当我尝试在 windows 上的 php 中执行此代码时:
shell_exec(R CMD BATCH test.R)
它给我一个错误:"Error in library(raster) : packages 'raster' was not found"
这没有任何意义,因为它在 unix 上工作!
几种可能性:
光栅包未安装
PHP 调用 shell_exec 时的 PATH 设置了不同的环境变量,因此它没有加载正确的库(尝试设置 R_LIBS 来修复它)。
尝试使用 r 的绝对路径而不是相对路径。
对于上面提到的R_LIBS: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/x.y/library’ for CRAN OS X builds), for R x.y.z.
来自他们 FAQ 的示例:
"path_to_R\bin\x64\Rgui.exe" HOME=p:/ R_LIBS=p:/myRlib
当我在命令提示符下编写这个脚本时,它工作正常:
R CMD BATCH test.R
但是,当我尝试在 windows 上的 php 中执行此代码时:
shell_exec(R CMD BATCH test.R)
它给我一个错误:"Error in library(raster) : packages 'raster' was not found"
这没有任何意义,因为它在 unix 上工作!
几种可能性:
光栅包未安装
PHP 调用 shell_exec 时的 PATH 设置了不同的环境变量,因此它没有加载正确的库(尝试设置 R_LIBS 来修复它)。
尝试使用 r 的绝对路径而不是相对路径。
对于上面提到的R_LIBS: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/x.y/library’ for CRAN OS X builds), for R x.y.z.
来自他们 FAQ 的示例:
"path_to_R\bin\x64\Rgui.exe" HOME=p:/ R_LIBS=p:/myRlib