【发布时间】:2016-12-07 18:23:05
【问题描述】:
我正在使用以下 php 代码来运行 R 语言的脚本。
echo "<form action='rtest1.php' method='get'>";
echo "Number values to generate: <input type='text' name='N' />";
echo "<input type='submit' />";
echo "</form>";
if(isset($_GET['N']))
{
$N = $_GET['N'];
// execute R script from shell
// this will save a plot at temp.png to the filesystem
$result=array();
$int='';
exec("D:\\R-2.14.0\\bin\\Rscript.exe D:\\wamp\\www\\R\\test.R 7 2 1");
}
这是我的 Rscript 的示例代码
args <- commandArgs(TRUE);
#assign data path
data_path <- "D:\\wamp\\www\\R";
#assign valus to the following three percent
train_per <- args[1];
test_per <- args[2];
val_per <- args[3];
我想将值 7,2 和 1 从 php 代码传递给 Rscript
exec("D:\\R-2.14.0\\bin\\Rscript.exe D:\\wamp\\www\\R\\test.R 7 2 1");
那我该怎么做呢。请帮忙
【问题讨论】:
-
看起来很好(除了外括号),你运行代码的时候有没有报错?如果它是“语法错误,意外的';',那么最有可能导致它的是外括号。
-
我必须问这个:你为什么不安装RApache?这种方法往往对代码注入友好。 =/
标签: php r command-line-arguments