Max
Max

Reputation: 2136

shell_exec requires full path name in php script on mac

(Doing this on OSX, apologize if off-topic)

When I run the line of code

shell_exec("/usr/local/bin/gnuplot gnuplot_script7"); 

inside a php script, a file named gnuplot_output7.png is generated, as expected. But when I run the similar line of code

shell_exec("gnuplot gnuplot_script7"); 

no image is generated! This despite that if I type

gnuplot gnuplot_script7

on the OSX command line, the image is successfully generated.

I typed - echo $PATH on the command line and got back

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/PostgreSQL/8.4/bin/:/usr/local/git/bin:/usr/X11/bin

and when I typed

which gnuplot

on the command line I got back

/usr/local/bin/gnuplot

Upvotes: 1

Views: 2835

Answers (1)

Pedro Lobito
Pedro Lobito

Reputation: 98971

Your user $PATH isn't the same as the user php is running.


Solution

1- Run php under your user (probably unsafe) and you can use:

shell_exec("gnuplot gnuplot_script7");

2 - Just use the full path:

 shell_exec("/usr/local/bin/gnuplot gnuplot_script7"); 

Upvotes: 2

Related Questions