I have self-writed sh script, which contains contruction like "cd directory"
It is successfully running through terminal
. /path/to/script.sh param1 param2
I want to run this script through PHP
shell_exec('. /path/to/script.sh param1 param2');
shell_exec('. /path/to/script.sh "param1" "param2"');
not running correctly
shell_exec('/bin/bash /path/to/script.sh param1 param2');
running, but directory changing is not working
Please, help. Thank you in advance
You're starting your command with .
- that will be interpreted as shell-source command, which is not what you want, obviously. Instead specify full path and do like:
$result = shell_exec('/bin/bash /full/path/to/script.sh param1 param2');
//var_dump($result);
-also, make sure your php user have permission to execute your sh-script and that PHP can use functions like exec()
(they could be disabled by configuration)
You need to use quotes to send arguments, try this :
$command_result = shell_exec('script.sh "'.$param1.'" "'.$param2."');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With