PHP exec $PATH variable missing elements(PHP exec $PATH 变量缺少元素)
问题描述
当我在命令行上回显 $PATH 时,它返回
When I echo $PATH on my command line, it returns
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/MAMP/Library/bin:/usr/local/git/bin:/usr/X11/bin
当我执行这段 php 代码时
When I execute this php code
exec('echo $PATH; whoami; less /etc/paths; 2>&1')
我明白
string 'echo $PATH; whoami; less /etc/paths; 2>&1' (length=56)
array
0 => string '/usr/bin:/bin:/usr/sbin:/sbin' (length=29)
1 => string 'eric' (length=4)
2 => string '/usr/bin' (length=8)
3 => string '/bin' (length=4)
4 => string '/usr/sbin' (length=9)
5 => string '/sbin' (length=5)
6 => string '/usr/local/bin' (length=14)
7 => string '/Applications/MAMP/Library/bin' (length=30)
8 => string '/usr/bin:/bin:/usr/sbin:/sbin' (length=29)
这是在 Mac OS X 上.谁能告诉我为什么我的最后两个路径元素丢失了?
This is on Mac OS X. Can anyone tell me why my last two path elements are missing?
推荐答案
Mac OS X 上的环境变量由不同的机制设置,具体取决于您的代码或其父进程的启动方式.为了确保从交互式 shell 启动的项目和由 WindowServer 启动的项目具有相同的路径,您需要使 ~/.MacOSX/environment.plist 与 .profile(或 .cshrc)中的设置保持同步.
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).
这篇关于PHP exec $PATH 变量缺少元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP exec $PATH 变量缺少元素
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01