1

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.

2
  • 1
    add babel's path to the script. Commented Mar 12, 2012 at 0:25
  • which shell and user is shell_exec using with your PHP configuration? Which shell and user are you using when you run it in your terminal? Do both configurations differ? If yes, in which points? Commented Mar 12, 2012 at 0:26

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks i seem to be getting somewhere now i get a Cannot write to a.smsi error im guessing this has somthing to do with permissions
1

Try calling babel with its absolute name. Use which babel to determine this, and replace 'babel' with it in your script.

2 Comments

thanks i seem to be getting somewhere now i get a Cannot write to a.smsi error im guessing this has somthing to do with permissions
Thankyou so much you've helped me so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.