exec() and system() are not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
s3rg1o
Forum Commoner
Posts: 32
Joined: Sun Feb 16, 2003 4:58 pm

exec() and system() are not working

Post by s3rg1o »

hey guys, I am hoping I can get some help from this forum, you guys helped me out before :D

ok so I am attempting to execute an outside app from php.. with exec or system and neither is working

here is what works

Code: Select all

<?

$output = system ("ls -l");

echo $output;

?>
same with exec()

but if I do something like....

Code: Select all

<?

$output = system ("mogrify -resize 640x480 shot0000.jpg");

echo $output;

?>
it will not do it, I know I am pointing to the right directory and everything aswell and I know that safe_mode is off in the php.ini

any suggestions? thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

does it not return or does it not perform the expected action?
I know I am pointing to the right directory
I do not see any path at all, is mogrify in one of the directories set by PATH for the webserver-account?
Is there anything in $output? And what should it be?
s3rg1o
Forum Commoner
Posts: 32
Joined: Sun Feb 16, 2003 4:58 pm

Post by s3rg1o »

hey vokla I believe you helped me with my problem I had before

and yeh I changed it so that it points to mogrify's path

Code: Select all

<?php

exec ('/home/web/pcgs/convert/utilities/mogrify -resize 640x480 /home/web/pcgm/shot0000.jpg', $output);



$output = ereg_replace ("\n", "<BR>", $output&#1111;0]);

echo $output;


?>

also, when I take out the modifiers

Code: Select all

<?php


exec ('/home/web/pcgs/convert/utilities/mogrify', $output);



$output = ereg_replace ("\n", "<BR>", $output&#1111;0]);

echo $output;


?>
it does print out the same thing that it does on the command prompt telling me to add what I need to add to the command but it's when I actually add the -resizing that it just will not work
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hm.. what was the solution last time?
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

the returned value is just the last line when using exec(), try something like

@exec('/bin/ls -l /home/user/dirtolist',$output);
echo "Output: <pre>\n". join('',$output);


if you are passing any commandline arguments from your script, make sure to always use escapeshelllarg() !!!
s3rg1o
Forum Commoner
Posts: 32
Joined: Sun Feb 16, 2003 4:58 pm

Post by s3rg1o »

Stroker, it didn't work

Code: Select all

<?php

escapeshellarg ('/home/web/pcgs/convert/utilities/mogrify -resize 640x480 /home/web/pcgm/shot0000.jpg', $output);



$output = ereg_replace ("\n", "<BR>", $output&#1111;0]);

echo $output;


?>
s3rg1o
Forum Commoner
Posts: 32
Joined: Sun Feb 16, 2003 4:58 pm

Post by s3rg1o »

volka wrote:hm.. what was the solution last time?
the solution was to a completely different problem
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

appending 2>&1 to the command revealed a filesystem permission problem. Would be nice if exec could fetch stderr on its own (maybe via flag parameter)
Post Reply