0

If I debug a command line app from Xcode, I get a different $PATH than if I run the same app from a terminal session.

For example, when run from a Terminal:

$env | grep "PATH="
//output: PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin

...
From an Xcode debug session:

let environment = ProcessInfo.processInfo.environment
print(environment["PATH"] ?? "No PATH found")
//output: /Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin

As a result, some command line apps are unavailable while debugging.

How do I get the terminal window $PATH environment variable within an Xcode debugging session?

ToddX61
  • 683
  • 6
  • 12
  • 1
    Xcode (and other GUI applications started from the Finder) do not read the user‘s .profile file. See https://stackoverflow.com/questions/135688/setting-environment-variables-on-os-x for some possible solutions. – Martin R May 03 '19 at 12:43

1 Answers1

1

As Martin R said in his comment, the environment passed to GUI programs is different than that used by shell applications.

I never found a simple solution to the problem. I suspect that the environment paths are set either with launchctl or a default is provided to GUI apps.

Finally, I ended up changing the environment used by class Process (Swift). Though not perfect (and certainly more complicated than I'd hoped), it works. You can find the entire implementation I used at: GitHub

ToddX61
  • 683
  • 6
  • 12