Page 1 of 1

Trouble with exec() and system()

Posted: Sat Sep 27, 2008 10:56 am
by The_Anomaly
Hey guys,


I'm having a ridiculous amount of trouble with this. I was told on this forum that using the $_FILE['name']['type'] to validate that the user submitted a video is stupid, so I thought I'd use ffmpeg to check if it's a video. The following command is all I need:

Code: Select all

ffmpeg -i /path/to/video/test.wmv
So, I have the PHP code:

Code: Select all

    echo exec('ffmpeg -i /path/to/encoder/test.wmv');
It returns nothing. I've tried with more basic commands, such as ls, or something similar, and it works perfectly. I"ve tried using system() instead of exec(), but again, to no avail. Nothing returns--as in, the page is blank.

If you guys could help me out, I'd appreciate it. The long and short of it is that I can't get exec() or system() to return the output of the command. I've tried using the second parameter of exec() to populate an array, but again, the array is null.

Please note that the command works seamlessly when ran from the server, as opposed to my php script.

Re: Trouble with exec() and system()

Posted: Sat Sep 27, 2008 11:55 am
by VladSun
Try

Code: Select all

echo system('/path/to/ffmpeg -i /path/to/encoder/test.wmv 2>&1');
PS: Though, I'm not sure what you expect to echo ...

Re: Trouble with exec() and system()

Posted: Sat Sep 27, 2008 12:02 pm
by The_Anomaly
VladSun wrote:Try

Code: Select all

echo system('/path/to/ffmpeg -i /path/to/encoder/test.wmv 2>&1');
Wow. You are the man. It freaking worked.

What on earth was this 2>&1 thing that made all the difference?

Thank you very much.

Re: Trouble with exec() and system()

Posted: Sat Sep 27, 2008 12:05 pm
by VladSun
The_Anomaly wrote:
VladSun wrote:Try

Code: Select all

echo system('/path/to/ffmpeg -i /path/to/encoder/test.wmv 2>&1');
Wow. You are the man. It freaking worked.

What on earth was this 2>&1 thing that made all the difference?

Thank you very much.
:)

0 - standard input;
1 - standard output;
2 - standard error output;

2>&1 - redirect standard error output to standard output.

system() and related functions return only standard output.

Re: Trouble with exec() and system()

Posted: Sat Sep 27, 2008 12:09 pm
by The_Anomaly
VladSun wrote:
The_Anomaly wrote:
VladSun wrote:Try

Code: Select all

echo system('/path/to/ffmpeg -i /path/to/encoder/test.wmv 2>&1');
Wow. You are the man. It freaking worked.

What on earth was this 2>&1 thing that made all the difference?

Thank you very much.
:)

0 - standard input;
1 - standard output;
2 - standard error output;

2>&1 - redirect standard error output to standard output.

system() and related functions return only standard output.
Wow, awesome. Tell me though, is this specific to *nix? Or is it something that has to do with PHP and would have the same effect in Windows?

i.e. Does Windows have a distinction between standard and standard error output?

Re: Trouble with exec() and system()

Posted: Sat Sep 27, 2008 4:38 pm
by VladSun