Solved

PHP exec() does not return result?

Posted on 2009-07-10
14
734 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is wrong with this PDO Delete Query? 2 17
Help with PHP 13 27
PHP: Best way to scan folders and process files 10 39
Php logic to add to date card 9 19
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

856 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