PHP system calls and $PATH in OS X

随声附和 提交于 2019-12-02 10:38:18

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!