Rscript does not work when invoked in PHP but does from Command Prompt

亡梦爱人 提交于 2019-12-13 17:45:53

问题


I am trying to execute an R script from my PHP page using the exec function. I have set the environment variables in Windows and Rscript works fine on the command prompt. However on the PHP page it says, " 'Rscript' is not recognized as an internal or external command, operable program or batch file."

Any help would be greatly appreciated.


回答1:


I would define a launcher.bat where I deal will all R-paths problem:

PATH PATH_TO_R/R-version/bin;%path%
cd PATH_TO_R_SCRIPT
Rscript myscript.R arg1 arg2

Then in the php side you can use exec:

   <?php
exec('c:\WINDOWS\system32\cmd.exe /c START PATH_TO_LAUNCHER\LAUNCHER.bat');
?>


来源:https://stackoverflow.com/questions/17817206/rscript-does-not-work-when-invoked-in-php-but-does-from-command-prompt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!