Solved

PHP exec() does not return result?

Posted on 2009-07-10
14
732 Views
Last Modified: 2013-12-13
Hi all,

   After a lot of trying I finally got ffmpeg working on my Windows 2008 machine. I can use it through the DOS cmd line and all seems just fine.

However, when I try to execute the application through exec() in php 5.3 I just get blank pages:

echo exec("d:\ffmpeg\bin\ffmpeg.exe", $aResult);

I added d:\ffmpeg to the open_basedir line in PHP, but that didn't help. Any ideas on this?

Not sure if this could be the problem, but I read something about giving the IIUSRS account execute rights on c:\windows\system32\cmd.exe. However, when I open the security tab in Windows 2008, the "add user/group" button is disabled.

If any other information could help to solve this, please ask!

Thanks!

Chris
0
Comment
Question by:HidDS
  • 8
  • 5
14 Comments
 
LVL 9

Expert Comment

by:wellhole
ID: 24826639
Just going out on a leg here... Does your page work if you comment out this line?
0
 

Author Comment

by:HidDS
ID: 24826666
Hehe, yeah pretty sure of that, when I do:

echo 'abc';
echo exec("d:\ffmpeg\bin\ffmpeg.exe", $aResult);
echo 'def';
print_r($aResult);

The result is:
abcdef
0
 

Author Comment

by:HidDS
ID: 24826675
P.s. When I run the exact same command in the DOS prompt I get a nice result from mmpeg.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:HidDS
ID: 24826990
It might just be the rights on the cmd.exe file, but why can't I add / alter permissions on this file in WIndows 2008, logged in as Administrator?
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24827566
exec() only returns the last line of the command output.

http://php.net/function.exec

Try this:
exec("d:\ffmpeg\bin\ffmpeg.exe", $aResult);
echo '<pre>'.implode("\n",$aResult).'</pre>';

Open in new window

0
 

Author Comment

by:HidDS
ID: 24829661
True, about returning only the last line, but also with this method I don't receive any result :(.
Strange thing is that programs like "ping" DO work... But I'm sure it works through the command line, so why should ffmpeg be different?
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24830208
When using backslashes within double quotes, the backslashes must be escaped with an additional backslash:

exec("d:\\ffmpeg\\bin\\ffmpeg.exe", $aResult);
echo '<pre>'.implode("\n",$aResult).'</pre>';

Alternatively, use single quotes:

exec('d:\ffmpeg\bin\ffmpeg.exe', $aResult);
echo '<pre>'.implode("\n",$aResult).'</pre>';

exec() has a third, optional parameter. You can use this to test if the command was successfull or not:
exec('d:\ffmpeg\bin\ffmpeg.exe', $aResult,$error);
if($error) echo '<p style="color:red">Error code: '.$error.'</p>';
echo '<pre>'.implode("\n",$aResult).'</pre>';

Open in new window

0
 

Author Comment

by:HidDS
ID: 24833883
I receive an error no. 1, but can't find the meaning of this error yet :).
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24833956
Did you fix the backslashes?

When executing ffmpeg without parameters, I get exitcode 1 (like you) and the message "At least one output file must be specified".
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24834064
I did some experiments. I have ffmpeg installed under C:\Program files. I could NOT get this to work:

exec('C:\Program files\ffmpeg\ffmpeg.exe -i test.avi test.flv', $aResult,$error);

...but this worked:

chdir('C:\Program files\ffmpeg');
exec('ffmpeg.exe -i test.avi test.flv', $aResult,$error);

However, I did NOT get any output in $aResult. I don't know why. But the program executed, the video was converted.
0
 

Author Comment

by:HidDS
ID: 24834230
I only received "1" as output, no messages about things that should be specified. The URL was altered (single quotes).

The background of the problem is that I want to display a FLV movie in an popup. In order to make this popup the right size for the movie, I need to retrieve the dimensions of the movie.

Herefor I planned to use: ffmpeg.exe -i xyz.flv and to filter out the dimensions of the movie. So no conversion is required, I really need the output of the command :(.
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24834339
Ok, I think I am on to something...

I checked my apache error logs, and found the output there. That means the output is sent to "standard error", not to "standard out". Try redirecting this output to a file, and read the file. Something like this:
chdir('C:\Program files\ffmpeg');
exec('ffmpeg.exe -i test.avi 2> test.info');
$info = file_get_contents('test.info');

Open in new window

0
 

Author Comment

by:HidDS
ID: 24834372
Great! This seems to work fine, I now receive the response of my ffmpeg command to work with!
Bit strange it is send to standard error in stead of standard out, but I'm glad you got this figured out (I was lost ;)).

Many thanks for your help, effort and time!
0
 

Author Closing Comment

by:HidDS
ID: 31602232
Thank you for your time!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now