如何使用 shell_exec 执行多行命令?
How to execute multi line command with shell_exec?
我正在尝试 运行 shell_exec
中的多行 shell
$cmd = <<<CMD
convert /home//test.jpg
-font Nimbus-Sans-L -pointsize 20 \
-draw "gravity south fill black text 0,12 'Copyright' fill white text 1,11 'Copyright' " \
test2.jpg
CMD;
我试过用 \ 和 \\ 甚至用 \\\ 也没有任何 !
正确的语法是什么?
您在命令的第一行缺少结尾的 \
反斜杠。应该是:
$cmd = <<<CMD
convert /home//test.jpg \
-font Nimbus-Sans-L -pointsize 20 \
-draw "gravity south fill black text 0,12 'Copyright' fill white text 1,11 'Copyright' " \
test2.jpg
CMD;
看到这按预期工作:
<?php
$cmd = <<<CMD
echo abc \
def \
ghi
CMD;
print_r(shell_exec($cmd));
$ php test.php
abc def ghi
我正在尝试 运行 shell_exec
中的多行 shell$cmd = <<<CMD
convert /home//test.jpg
-font Nimbus-Sans-L -pointsize 20 \
-draw "gravity south fill black text 0,12 'Copyright' fill white text 1,11 'Copyright' " \
test2.jpg
CMD;
我试过用 \ 和 \\ 甚至用 \\\ 也没有任何 !
正确的语法是什么?
您在命令的第一行缺少结尾的 \
反斜杠。应该是:
$cmd = <<<CMD
convert /home//test.jpg \
-font Nimbus-Sans-L -pointsize 20 \
-draw "gravity south fill black text 0,12 'Copyright' fill white text 1,11 'Copyright' " \
test2.jpg
CMD;
看到这按预期工作:
<?php
$cmd = <<<CMD
echo abc \
def \
ghi
CMD;
print_r(shell_exec($cmd));
$ php test.php
abc def ghi