PHP从shell脚本获取变量

时间:2017-07-05 21:44:43

标签: php shell-exec

php如何从shell脚本获取变量。 我有:shell_exec('php /var/www/html/test/kobi.php $param1'); 我想收到$parm1 in kobi.php 我试着这样做:$imsi=$argv[1]; 但它不起作用。 谁能解释一下是什么错? 我该怎么做呢?

1 个答案:

答案 0 :(得分:0)

您使用了错误的功能try exec而不是

http://php.net/manual/en/function.exec.php

  

exec(string $ command [,array& $ output [,int& $ return_var]])

   $param1 = escapeshellarg( $param1 );
   exec('php /var/www/html/test/kobi.php $param1', $output );

并使用它。

http://php.net/manual/en/function.escapeshellarg.php

否则有人会接管你的服务器......

<强> 更新

'php /var/www/html/test/kobi.php $param1'

是字符串文字,所以你的输入字面意思是$param1,而不是它的值。顺便说说。您可以使用"双引号进行变量插值。