0

How can php get variable from shell script. I have: shell_exec('php /var/www/html/test/kobi.php $param1'); And i want to recieved $parm1 in kobi.php I tried to do it with: $imsi=$argv[1]; but it doesn't work. can someone explain what's wrong? How should i do that correct?

K.D
  • 21
  • 6
  • it contains nothing ...., because the script executing inside of `shell_exec` is running in a separate thread, and `$argv` is for this thread. I use the term thread loosely. Instance of PHP is probably more "proper" – ArtisticPhoenix Jul 05 '17 at 21:53

1 Answers1

0

You use the wrong function try exec instead

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 );

And use this too.

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

Otherwise someone take over your server maybee...

UPDATE

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

Is string literal, so your input is $param1 literally, not the value of it. By the way. You would use " double quotes for variable interpolation.

ArtisticPhoenix
  • 21,464
  • 2
  • 24
  • 38