沃梦达 / 编程问答 / php问题 / 正文

PHP exec $PATH 变量缺少元素

PHP exec $PATH variable missing elements(PHP exec $PATH 变量缺少元素)

本文介绍了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 变量缺少元素

基础教程推荐