PHP exec() function acting strange

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomjmul
Forum Newbie
Posts: 3
Joined: Tue Feb 21, 2006 1:44 pm

PHP exec() function acting strange

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
tomjmul
Forum Newbie
Posts: 3
Joined: Tue Feb 21, 2006 1:44 pm

Post 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
tomjmul
Forum Newbie
Posts: 3
Joined: Tue Feb 21, 2006 1:44 pm

Post 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.
Post Reply