使用PHP运行命令行命令

使用PHP运行命令行命令,php,ubuntu,command-line,Php,Ubuntu,Command Line,因此,我的问题是:我的Ubuntu 18.04.3服务器上有一个R标记文件,我想通过命令行编写它(这适用于Rscript-e“rmarkdown::render('path/to/file.Rmd')”),所以我尝试使用exec()命令从PHP运行它(显然使用转义字符)。PHP的输出如下所示: 执行暂停数组([0]=>错误:在“rmarkdown::render(\”[1]=>执行暂停)中出现意外输入 运行以下PHP行时: exec("Rscript -e \"rmarkdown::render

因此,我的问题是:我的Ubuntu 18.04.3服务器上有一个R标记文件,我想通过命令行编写它(这适用于
Rscript-e“rmarkdown::render('path/to/file.Rmd')”
),所以我尝试使用exec()命令从PHP运行它(显然使用转义字符)。PHP的输出如下所示:
执行暂停数组([0]=>错误:在“rmarkdown::render(\”[1]=>执行暂停)中出现意外输入
运行以下PHP行时:

exec("Rscript -e \"rmarkdown::render(\'path/to/file.Rmd\')\" 2>&1", $output);
print_r($output); 

什么是意外输入?

不要逃避内部的

exec(“Rscript-e\”rmarkdown::render('path/to/file.Rmd')\“2>&1”,$output);

..或将最外层的字符串更改为使用单引号而不是双引号:

exec('Rscript-e“rmarkdown::render(\'path/to/file.Rmd\'))“2>&1',$output);

除非你同时使用这两种方法,否则不要逃避这两种方法,这既丑陋又令人困惑


exec(“Rscript-e\”rmarkdown::render(\\\\\\\\\\\\\\\\\“path/to/file.Rmd\\\\”)“2>&1”,$output);

为什么这个答案是正确的?为什么原来的版本在双引号中包含转义双引号不起作用?@RedBassett谢谢编辑,我急忙发帖,正在编辑,但你做到了,很高兴它起到了作用。《红色引号》每次都会得到你的