小编use*_*387的帖子

将多个PHP变量传递给shell_exec()?

我使用shell_exec方法从PHP调用test.sh.

$my_url="http://www.somesite.com/";
$my_refer="http://www.somesite.com/";
$page = shell_exec('/tmp/my_script.php $my_url $my_refer');
Run Code Online (Sandbox Code Playgroud)

但是,命令行脚本说它只收到一个参数:/tmp/my_script.php

当我将呼叫更改为:

码:

$page = shell_exec('/tmp/my_script.php {$my_url} {$my_refer}');
Run Code Online (Sandbox Code Playgroud)

它说它接收了3个参数,但是argv [1]和argv [2]是空的.

当我将呼叫更改为:

码:

$page = shell_exec('/tmp/my_script.php "http://www.somesite.com/" "http://www.somesite.com/"');
Run Code Online (Sandbox Code Playgroud)

该脚本最终按预期接收所有3个参数.

您是否始终只需使用脚本发送带引号的文本,并且不允许发送像$ var这样的变量?或者有一些特殊的方式你必须发送$ var?

php shell shell-exec

19
推荐指数
3
解决办法
6万
查看次数

标签 统计

php ×1

shell ×1

shell-exec ×1