views:

58

answers:

1

I'm trying to get PHP to make system calls on OS X. However, it doesn't seem to be able to find anything that's included in the system path.

When I run...

putenv("PATH={$_SERVER["PATH"]}:/usr/local/bin");

... just before the system call, it works. This is not a practical solution, since the code that executes the system call is a plugin, so I'd rather not touch source code that'll make it incompatible come an update.

Apache2 is running as the same user as I'm logged in, so theoretically it has access to the same commands as me.

Also, the same code works fine on my Ubuntu machine.

A: 

Environment variables on Mac OS X are set by differing mechanisms depending on how your code, or its parent process, was launched. To insure that items launched from an interactive shell and items launched by the WindowServer have the same path, you need to keep ~/.MacOSX/environment.plist in sync with what is set in .profile (or .cshrc).

The simplest means of accomplishing your goal without having to resort to editing the environment would be to specify a temporary path for what you are executing via your system command. e.g.:

char cmdStr[512] = "PATH=$PATH:/usr/local/bin";
strncat(cmdStr,"MyCommand", 9);
system(cmdStr);

This way the environment is only affected for the context of MyCommand and restored afterwards.

CuriousRabbit
Thanks! Since environment.plist doesn't exist for my user (probably the problem), can I simply softlink it to .profile? Using a PHP hack is not really an option since the offending system call is in a plugin.
Henrik
No, that won't work. Those files are in different formats and need to have different content. See http://developer.apple.com/library/mac/#qa/qa2001/qa1067.html
CuriousRabbit