An example of how to call a shell script with php
This site has some interesting code to modify images and I ran the code by:
- Download the script and upload it to your server.
- Change the permissions to 755 on the script
- Write your php code like this using the full path to the script
<?php
// Run the script
exec("/FULL PATH TO AUTOTRIM/autotrim.sh zelda3_border2w.png fred.png 2>&1", $array);
//Display any errors
echo "<br>".print_r($array)."<br>";
echo "</pre>";
?>
When I ran the code I recived an error:
/autotrim.sh: line 271: bc: command not found
bc is a calculator that is built into Unix/Linux.
I ran this code to get some information about the path for bc and it did not return anything so I assumed bc was not installed.
I contacted my hosts who installed it and the code worked OK.
<?php
echo "<pre>";
system('which bc',$path); print_r($path);
echo "</pre>";
?>
I was also told that I may have been able to install the bc binarys ( although I could not find them ) and use the path to those in the code. I did not need to try that so I do not know if it would have worked or not.