Page 1 of 1

PHP exec() function acting strange

Posted: Tue Feb 21, 2006 1:56 pm
by tomjmul
I am trying to call a system command with the exec function and am getting a result which I don't really understand.

The first command I am using works perfectly:

Code: Select all

$norm = `/usr/bin/sox $inputfile -e stat -v 2>&1`;
This uses sox to calculate the max gain which a sound file can be increased by before clipping.

Now, after I get the correct value, I want to actually increase the gain, so I use:

Code: Select all

$result = `/usr/bin/sox -v $norm $inputfile $outputfile 2>&1`;
This is where it gets a bit strange; Instead of the sox command executing in this case, it seems as though the shell is trying to execute the file contained in the $inputfile var, and so I get the following:

sh: line 1: /var/lib/asterisk/sounds/sphinx_1140504120.117.wav: cannot execute binary file


This has been driving me nuts for over a day, and I just can't think of a solution. I have changed php.ini so that all of the safe mode stuff is off.

Does anyone have any ideas?

Many thanks.

Posted: Tue Feb 21, 2006 3:16 pm
by pickle
Try echoing the command before you execute it - just to see if it's formatted properly.

What happens if you try to execute /usr/bin/sox -v $norm $inputfile $outputfile 2>&1 from the command line (of course, replacing all the variables with their appropriate value)

Posted: Tue Feb 21, 2006 3:32 pm
by tomjmul
Yes have tried that, indeed here is the full string which is still in my debug log:

Code: Select all

sox -v 1.334  /var/lib/asterisk/sounds/sphinx_1140504120.117.wav var/lib/asterisk/sounds/norm_sphinx_1140504120.117.wav
copied directly to the command line, it does of course work perfectly

Posted: Tue Feb 21, 2006 3:48 pm
by tomjmul
Holy sweet christ, I've finally got it!!
Just as I was pasting that bit of code in, I noticed that the line had broke after the normalization value. The first command was returning a line break after the value which was being carried over into the second command.

A quick $norm=trim($norm); has now done the trick.