godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.93k stars 20.17k forks source link

MacOSX OS.get_enviroment("PATH") and OS.execute() do not use correct env path, but use a a different version, thereby running an app from wrong path. #96409

Open wyattbiker opened 2 weeks ago

wyattbiker commented 2 weeks ago

Tested versions

v4.3.stable.official [77dcf97d8]

System information

Mac OS X Catalina 10.15

Issue description

On Mac OSX, the Environment PATH is different when retrieving it using gdscript than from the BASH command line. This cause confusion if you are for example running OS.execute("which",["awk"], value, true, true) to locate an application to execute. This issue doesn't appear on Linux using same commands.

To verify I copied a test version of /usr/bin/awk to /usr/local/bin/awk and then used BASH commands followed by gdscript.

First tested from command line: MacOSX Bash commands to determine shell and path

~$ echo $SHELL
/bin/bash
~$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:
~$ which awk
/usr/local/bin/awk

Now test with Godot same commands using gdscript. PATH comes up different, even though the shell is BASH.

    print(OS.get_environment ("SHELL")) #/bin/bash
    print(OS.get_environment ("PATH")) #/usr/bin:/bin:/usr/sbin:/sbin
    var value=[]
    var err=OS.execute("which",["awk"], value, true, true)
    prints(err, value) #0 ["/usr/bin/awk\n"]

Steps to reproduce

see above

Minimal reproduction project (MRP)

na

bruvzg commented 2 weeks ago

This is expected behavior, macOS GUI apps do not use shell environment by default, and it's impossible to change PATH for the GUI apps (globally, app itself can change it), sandboxed apps distributed via App Store can't use it at all.

See https://github.com/godotengine/godot/pull/81266 (which implement workaround).

wyattbiker commented 1 week ago

Will this be backported you think?