使用PHP运行命令行命令

耶利米·波恩(Jeremiah Bohn):

所以我的问题如下:我的Ubuntu 18.04.3服务器上有一个R markdown文件,我想通过命令行进行编织(这与可以很好地结合使用Rscript -e "rmarkdown::render('path/to/file.Rmd')"),所以我尝试使用exec()命令从PHP运行它(显然使用转义字符)。PHP的输出如下:Execution haltedArray ( [0] => Error: unexpected input in "rmarkdown::render(\" [1] => Execution halted )运行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);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章