[英]Running a command line command with PHP
所以我的问题如下:我的 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 时, Execution haltedArray ( [0] => Error: unexpected input in "rmarkdown::render(\\" [1] => Execution halted )
:
exec("Rscript -e \"rmarkdown::render(\'path/to/file.Rmd\')\" 2>&1", $output);
print_r($output);
什么是意外输入?
不要逃避内心'
' s
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.