?
Solved

PHP exec() does not return result?

Posted on 2009-07-10
14
Medium Priority
?
745 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
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.
Suggested Courses

764 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