shell_exec issues

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
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

shell_exec issues

Post by d3ad1ysp0rk »

Hey everyone. Need a bit of help.

Code: Select all

<?php
$pwdOutput = shell_exec("pwd");
$sOutput = shell_exec("convert ../images/team//24antilame.gif -thumbnail 60x40 ../images/team//thumbs/24antilame.gif");
echo "PWD: " . $pwdOutput . "<br />";
echo "Out: " . $sOutput;
die();
?>
Alright, here's the deal. If I execute that code, I get this:

Code: Select all

Pwd: /home/sites/site45/web/control
Out:
So; no output. Not a big deal, because when you use convert (imageMagick), it shouldn't spit anything out. Here's the problem though; it doesn't actually do the conversion (create a thumbnail).

So I'm thinking "maybe I messed up the syntax of the call..", but no.. when I cd to what pwd prints out, and then paste the exact call I'm sending to shell_exec, it works.

Any ideas? This is so confusing.. :?
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Post by R4000 »

try passthru().
I use it for everything like this...


passthru
(PHP 3, PHP 4, PHP 5)
passthru -- Execute an external program and display raw output

Description
void passthru ( string command [, int &return_var] )

The passthru() function is similar to the exec() function in that it executes a command. This function should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser. A common use for this is to execute something like the pbmplus utilities that can output an image stream directly. By setting the Content-type to image/gif and then calling a pbmplus program to output a gif, you can create PHP scripts that output images directly.

Parameters
command
The command that will be executed.
return_var
If the return_var argument is present, the return status of the Unix command will be placed here.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Changing it to

Code: Select all

passthru("command",$sOutput);
printed this result: "127"

I googled it, and it seems like a php OR imagemagick error, stating "file not found" or something..

team directory is "drwxrwxrwx" as is thumbs directory.

Any ideas? :\
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

does getcwd() say something different than `pwd` ?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Unfortunately no,

Code: Select all

Cwd: /home/sites/site45/web/control
Pwd: /home/sites/site45/web/control
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Is the convert tool in your webservers path?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

timvw wrote:Is the convert tool in your webservers path?
I'm not the sysadmin, and I'm no unix pro.. where would the config file for finding out be?
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Post by R4000 »

passthru() outputs the raw data, i don't know what format this might be in, cause personaly... ive never needed output from a command line app.
If it can't be done in PHP then do it in another language, don't split it across two xD

ImageMagik is a nice application, but if you just want the resize stuff.. use GD, same for convert.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

R4000 wrote:passthru() outputs the raw data, i don't know what format this might be in, cause personaly... ive never needed output from a command line app.
If it can't be done in PHP then do it in another language, don't split it across two xD

ImageMagik is a nice application, but if you just want the resize stuff.. use GD, same for convert.
GD isn't installed, and there is no way for it to be at this time. The site needs to go live, so I need to use what's available. :?

I don't really understand how I'm splitting it across languages; I'm letting the user upload an image which I'm resizing with imagemagick. MagickWand for PHP isn't installed, so I need to use the command line version..

Also, I still haven't figured out whether it's in apache's path, so how would I find that out?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Incase anyone finds this by searching and wants to know the solution;

Apache could not find the program. To rectify this, you just need to specify the exact path.

The reason I did not try this to begin with is because I had no idea where it was located. I found out by searching through other sites on the same server and finding their image thumbnailing code.

Thanks for the help everyone
Post Reply