running shell script from php
Question
I have a shell script which works perfectly if I run it in the terminal (MAC OSX)
#!/bin/bash
cd /Applications/XAMPP/xamppfiles/htdocs/chemedit/
babel -imol 'a.mol' -oinchi 'outputfile.inchi'
babel -imol 'a.mol' -osmi 'a.smsi'
babel a.smi -O out.svg -xC -xe
exit
I have this in a file called a.sh
I want to run this from PHP using:
$output = shell_exec("bash a.sh 2>&1");
This does not work and returns:
Cannot write to outputfile.inchi
0 molecules converted
1 errors
for all files
I have given both files chmod 777.
I am pretty sure safe mode is off for PHP.
Solution
Try calling babel with its absolute name. Use which babel
to determine this, and replace 'babel' with it in your script.
OTHER TIPS
The babel
command is likely not in the PATH
environment variable for the user running PHP, and thus the script via PHP. The simplest solution is to edit your shell script to refer to babel by its full path.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow