Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP exec() does not return result?

Posted on 2009-07-10
14
Medium Priority
?
754 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

782 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