LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-19-2007, 09:22 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
PHP: can't exec some programs when run through apache. why?


I can do this, no problem:
PHP Code:
if (!exec('ls',$output)){
  echo 
"bad exec<br>\n";
}else{
  echo 
"good exec<br>\n";
  foreach (
$output as $i){
    echo 
"$i<br>\n";

but I can't do this:
PHP Code:
if (!exec('/usr/bin/tcprobe',$output)){
  echo 
"bad exec<br>\n";
}else{
  echo 
"good exec<br>\n";
  foreach (
$output as $i){
    echo 
"$i<br>\n";

... unless I do it on the command line, i.e. "php foo.php" - in which case it does what I expect, which is spit out what tcprobe spits out.

If I try to do it through a browser, I get "bad exec" for the latter, however, the former (exec ls) works fine.

any ideas why this would be happening?
 
Old 04-20-2007, 03:06 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu
Posts: 1,198

Rep: Reputation: 76
maybe a permission problem unless /usr/bin/tcprobe is executable for everybody including apache user
 
Old 04-20-2007, 03:26 AM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by j-ray
maybe a permission problem unless /usr/bin/tcprobe is executable for everybody including apache user
hmm.. I thought I put that in my original post, but I guess I edited it out. Yes, tcprobe is executable by all.

I've made a bit of progress, however, but it has uncovered more mysteries -

if I make stderr go to stdout, I get the expected results even through the browser:

PHP Code:
if (!exec('/usr/bin/tcprobe 2>&1',$output,$error)){
  echo 
"bad exec<br>\n";
  echo 
"error: $error<br>\n";
}else{
  echo 
"good exec<br>\n";
  
$count 0;
  echo 
"<br>";
  foreach (
$output as $i){
    echo 
"$count - $i<br>\n";
    
$count++;
  }

which returns this:
Code:
good exec

0 - tcprobe (transcode v1.0.2) (C) 2001-2003 Thomas Oestreich
1 -
2 - Usage: tcprobe [options] [-]
3 - -i name input file/directory/device/host name [stdin]
4 - -B binary output to stdout (used by transcode) [off]
5 - -H n probe n MB of stream [1]
6 - -s n skip first n bytes of stream [0]
7 - -T title probe for DVD title [off]
8 - -b bitrate audio encoder bitrate kBits/s [128]
9 - -f seekfile seek/index file [off]
10 - -d verbosity verbosity mode [1]
11 - -v print version
However, if I pass a real arg to tcprobe, I only get the first line of output. The following code outputs the next bit:
PHP Code:
if (!exec("/usr/bin/tcprobe -i $vid 2>&1",$output,$error)){
  echo 
"bad exec<br>\n";
  
$count 0;
  echo 
"error: $error<br>\n";
}else{
  echo 
"good exec<br>\n";
  
$count 0;
  echo 
"<br>";
  foreach (
$output as $i){
    echo 
"$count - $i<br>\n";
    
$count++;
  } 
Code:
good exec

0 - [tcprobe] Apple QuickTime movie file
... but it *should* output this:
Code:
[tcprobe] Apple QuickTime movie file
[probe_mov.c] video codec=jpeg
[tcprobe] summary for Hummer.mov, (*) = not default, 0 = not detected
import frame size: -g 720x486 [720x576] (*)
       frame rate: -f 30.000 [25.000] frc=5 (*)
   no audio track: use "null" import module for audio
           length: 901 frames, frame_time=33 msec, duration=0:00:30.033
... which is what it does output if I run the php from the command line.

Any ideas?
 
Old 09-20-2007, 04:10 PM   #4
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
I know this is an old thread, but in the interest of answering all my questions that I find an answer to, here's the deal:

tcprobe appears to use multiple programs to accomplish what it's trying to do, i.e., it's a wrapper (i didn't know this until I looked through the source code, as tcprobe is a binary). That being the case, the tcprobe output (which is just the first line) outputs fine, however, the output from the programs that tcprobe calls goes elsewhere - I don't know where. To solve this problem, I used ffmpeg which is not a wrapper, but a full program in and of itself. The last code that I posted works fine with ffmpeg & does what I would expect it to.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help using exec() with php to run BitTornado linux nsdothack Linux - Software 0 03-18-2007 05:33 PM
Apache 2, PHP 5, SuSE 9.2 - cannot run php files dickohead Linux - Networking 6 06-28-2006 10:25 AM
PHP exec() on Apache - Privileges Problem Calltor Linux - Security 13 06-09-2006 09:04 AM
php: exec can't run lynx after apache restart BrianK Programming 4 01-16-2006 05:47 PM
php exec() function in chrooted apache clau_bolson Linux - Software 2 12-21-2005 08:29 AM


All times are GMT -5. The time now is 06:42 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration