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 变量缺少元素
基础教程推荐
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01