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?
Asked
Active
Viewed 822 times
0

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 Answers
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
-
-
`echo` literally? because `print_r()` `var_export()`, `var_dump()` are for arrays, you can't echo an array. – ArtisticPhoenix Jul 05 '17 at 21:56
-
-
Then run your script on the command line and see if it outputs anything, chances are it's not. – ArtisticPhoenix Jul 05 '17 at 21:58
-
-
Also on windows the php.exe should be configured in the PATH environmental variable, otherwise you have to use the full path to the php executable. – ArtisticPhoenix Jul 05 '17 at 22:03
-
Yes it looks like " solved it, thank you!! but now i facing a problem to pass an array. im passing an array and when i prin it by print_r($arr) im getting "array". whats wrong now? – K.D Jul 05 '17 at 22:38
-
-
-
that said, you can convert the array to Json, or a CSV, and pass that in, then convert it back. – ArtisticPhoenix Jul 06 '17 at 06:29
-
Ok, i solved it by appending array to string (with foreach loop) and passing it as a string, and after that bring it back to an array with explode. – K.D Jul 06 '17 at 07:33
-
-