Reputation: 21
I to want call a bash function with 'exec'/'bash_exec' in PHP, and then get the result back into PHP code. Something like:
<?php
..
..
//bash funct. definitions
$my_bash_function_path='/usr/bin/ls';
$my_bash_param1='x1';
$my_bash_param2='dsfx1';
//clling bash function
exec( $my_bash_function_path." ".$my_bash_param1." ".$my_bash_param2 );
//doing something with a result of bash function
echo ("some_output_of_bash_function");
..
..
?>
How should I do it?
Upvotes: 1
Views: 1385
Reputation: 122
you could also run the bash command like this:
$command=$my_bash_function_path." ".$my_bash_param1." ".$my_bash_param2;
$results=`$command`;
echo $results;
backticks makes php execute the string inside and return the result
Upvotes: 0
Reputation: 22152
Take a look at the signature of the function:
string exec ( string $command [, array &$output [, int &$return_var ]] )
If you use the second parameter of the exec
function, you'll get the output. More details here: http://php.net/manual/en/function.exec.php
Upvotes: 1