Page 1 of 1

Trying to use shell_exec, exec, system, passthru, etc.

Posted: Thu Jan 28, 2010 3:18 am
by Luke
I'm attempting to use a library called "ffmpeg" to convert mpeg files to flv on the fly when users upload them. I have downloaded and installed "ffmpeg" on my server and when I use it over ssh, it works exactly as expected. But for some reason, when I try the same exact command using "exec()", "shell_exec()", "system()", the back-tick operator, etc. it doesn't work.

Does anybody know why these functions would not work? PHP is running as the same user I was using for SSH, so it isn't that. Any other suggestions? :(

Re: Trying to use shell_exec, exec, system, passthru, etc.

Posted: Thu Jan 28, 2010 4:04 am
by Eran
It's probably permissions. Are you sure PHP is running as the same user? it usually runs as apache or nobody

Re: Trying to use shell_exec, exec, system, passthru, etc.

Posted: Thu Jan 28, 2010 6:38 am
by VladSun
Try

Code: Select all

echo `/full/path/to/ffmpeg ..... 2>&1`;

Re: Trying to use shell_exec, exec, system, passthru, etc.

Posted: Thu Jan 28, 2010 8:59 am
by Luke
pytrin wrote:It's probably permissions. Are you sure PHP is running as the same user? it usually runs as apache or nobody
Well, I ran "passthru('whoami')" inside PHP and it output "tvmed".

Re: Trying to use shell_exec, exec, system, passthru, etc.

Posted: Thu Jan 28, 2010 9:05 am
by Luke
VladSun wrote:Try

Code: Select all

echo `/full/path/to/ffmpeg ..... 2>&1`;
Forgive my ignorance, but what parts of that do you mean literally and what parts do you mean to replace args etc. with? Did you mean something like:

Code: Select all

echo `/usr/local/bin/ffmpeg '/path/to/file.mpeg' '/path/to/file.flv'`
Or did you mean to output the 2>&1 part literally?

Re: Trying to use shell_exec, exec, system, passthru, etc.

Posted: Thu Jan 28, 2010 10:02 am
by VladSun

Code: Select all

echo `/usr/local/bin/ffmpeg '/path/to/file.mpeg' '/path/to/file.flv' 2>&1`;
Shame on you - viewtopic.php?f=1&t=88741 :P :twisted: