Solved

PHP exec() does not return result?

Posted on 2009-07-10
14
729 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
Comment Utility
Just going out on a leg here... Does your page work if you comment out this line?
0
 

Author Comment

by:HidDS
Comment Utility
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
Comment Utility
P.s. When I run the exact same command in the DOS prompt I get a nice result from mmpeg.
0
 

Author Comment

by:HidDS
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

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

Expert Comment

by:Roger Baklund
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you for your time!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 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

10 Experts available now in Live!

Get 1:1 Help Now