Page 1 of 1

exec() and system() are not working

Posted: Wed Feb 26, 2003 3:22 pm
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

Posted: Wed Feb 26, 2003 4:11 pm
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?

Posted: Wed Feb 26, 2003 4:26 pm
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

Posted: Wed Feb 26, 2003 4:48 pm
by volka
hm.. what was the solution last time?

Posted: Wed Feb 26, 2003 5:31 pm
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() !!!

Posted: Wed Feb 26, 2003 5:51 pm
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;


?>

Posted: Wed Feb 26, 2003 5:52 pm
by s3rg1o
volka wrote:hm.. what was the solution last time?
the solution was to a completely different problem

Posted: Wed Feb 26, 2003 9:56 pm
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)