ProcessBuilder 从错误的 /bin 调用命令

ProcessBuilder calling commands from wrong /bin

我在 github 上有一个回购协议,每当有来自拉取请求的合并时,我想拉取最新的主分支。我有一个处理获取该请求的 springboot 应用程序,并且我有一个脚本来为我处理拉动。 springboot 应用程序在事件发生时通过 ProcessBuilder 运行此脚本,但我不断从脚本内的命令中收到“找不到命令”错误(sudo 运行 命令作为不同的用户,特别是 git ).

我是 运行 Pop!_OS,一个基于 Ubuntu 的 Linux 发行版,我使用 Eclipse 作为我的 IDE。

我已经检查过程序认为它是哪个用户,它作为我的用户回显。我已确保该路径包含 /bin/usr/bin 等内容。我将我的 PATH 复制为 eclipse 中的环境参数。我试过在脚本中使用命令的绝对路径,例如 /bin/git/usr/bin/git。 None 其中有效。我决定执行 ls 以查看 ProcessBuilder 在 /bin/usr/bin 中从它的角度看到了哪些文件,并注意到它似乎缺少我可以看到的文件,例如 git,我想这就是为什么它显然找不到的原因。

ProcessBuilder 运行脚本时用户回显:evan

ProcessBuilder 运行脚本时回显的路径:/home/evan/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/srv/minecraft/bin

ProcessBuilder 给出的错误:/srv/minecraft/bin/bashpull: line 38: git: command not found

有谁知道为什么 ProcessBuilder 似乎看不到与它认为的用户相同的文件,而当我是用户时我可以看到这些文件?

示例 - 在 /bin 中寻找 git:

ProcessBuilder ProcessBuilder /bin ls

My user /bin ls

[编辑] 我在我的文件系统中搜索了我发布的屏幕截图中的命令之一,我的 ProcessBuilder 看到并发现我的 ProcessBuilder 似乎出于某种原因位于这些文件夹中:

Directory path where ProcessBuilder is looking

这是在我的 ProcessBuilder 上设置的所有环境参数。我在想这里可能有什么东西导致 ProcessBuilder 被降级到另一个目录 运行 东西。

Key = PATH, Value = /home/evan/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/srv/minecraft/bin
Key = LC_MEASUREMENT, Value = en_US.UTF-8
Key = XAUTHORITY, Value = /run/user/1000/Xauthority
Key = INVOCATION_ID, Value = aa620309e8eb40119f6fccf9759a9f47
Key = XMODIFIERS, Value = @im=ibus
Key = LC_TELEPHONE, Value = en_US.UTF-8
Key = XDG_DATA_DIRS, Value = /app/share:/usr/share:/usr/share/runtime/share:/run/host/user-share:/run/host/share
Key = GDMSESSION, Value = pop
Key = MANDATORY_PATH, Value = /usr/share/gconf/pop.mandatory.path
Key = LC_TIME, Value = en_US.UTF-8
Key = PAPERSIZE, Value = letter
Key = GTK_IM_MODULE, Value = ibus
Key = DBUS_SESSION_BUS_ADDRESS, Value = unix:path=/run/user/1000/bus
Key = PS1, Value = [ $FLATPAK_ID \W]$ 
Key = DEFAULTS_PATH, Value = /usr/share/gconf/pop.default.path
Key = XDG_CACHE_HOME, Value = /home/evan/.var/app/org.eclipse.Java/cache
Key = XDG_CURRENT_DESKTOP, Value = pop:GNOME
Key = JOURNAL_STREAM, Value = 8:44922
Key = SSH_AGENT_PID, Value = 3053
Key = LC_PAPER, Value = en_US.UTF-8
Key = SESSION_MANAGER, Value = local/pop-os:@/tmp/.ICE-unix/3208,unix/pop-os:/tmp/.ICE-unix/3208
Key = USERNAME, Value = evan
Key = ALSA_CONFIG_PATH, Value = /usr/share/alsa/alsa-flatpak.conf
Key = LOGNAME, Value = evan
Key = GST_PLUGIN_SYSTEM_PATH, Value = /app/lib/gstreamer-1.0:/usr/lib/extensions/gstreamer-1.0:/usr/lib/x86_64-linux-gnu/gstreamer-1.0
Key = PWD, Value = /home/evan
Key = MANAGERPID, Value = 2266
Key = MATHEMATICA_HOME, Value = /usr/local/Wolfram/Mathematica/12.1
Key = LANGUAGE, Value = en_US:en
Key = GJS_DEBUG_TOPICS, Value = JS ERROR;JS LOG
Key = SHELL, Value = /bin/sh
Key = LC_ADDRESS, Value = en_US.UTF-8
Key = GIO_LAUNCHED_DESKTOP_FILE, Value = /home/evan/.local/share/flatpak/exports/share/applications/org.eclipse.Java.desktop
Key = AT_SPI_BUS_ADDRESS, Value = unix:path=/run/user/1000/at-spi-bus
Key = GNOME_DESKTOP_SESSION_ID, Value = this-is-deprecated
Key = GTK_MODULES, Value = gail:atk-bridge:appmenu-gtk-module
Key = ALSA_CONFIG_DIR, Value = /usr/share/alsa
Key = XDG_SESSION_DESKTOP, Value = pop
Key = SHLVL, Value = 0
Key = LC_IDENTIFICATION, Value = en_US.UTF-8
Key = LC_MONETARY, Value = en_US.UTF-8
Key = OXYGEN_DISABLE_INNER_SHADOWS_HACK, Value = 1
Key = QT_IM_MODULE, Value = ibus
Key = XDG_CONFIG_DIRS, Value = /app/etc/xdg:/etc/xdg
Key = LANG, Value = en_US.UTF-8
Key = XDG_SESSION_TYPE, Value = x11
Key = FLATPAK_SANDBOX_DIR, Value = /home/evan/.var/app/org.eclipse.Java/sandbox
Key = DISPLAY, Value = :99.0
Key = GI_TYPELIB_PATH, Value = /app/lib/girepository-1.0
Key = LC_NAME, Value = en_US.UTF-8
Key = XDG_SESSION_CLASS, Value = user
Key = _, Value = /usr/bin/dbus-update-activation-environment
Key = FLATPAK_ID, Value = org.eclipse.Java
Key = XDG_DATA_HOME, Value = /home/evan/.var/app/org.eclipse.Java/data
Key = LIBOVERLAY_SCROLLBAR, Value = 0
Key = GDK_CORE_DEVICE_EVENTS, Value = 1
Key = GPG_AGENT_INFO, Value = /run/user/1000/gnupg/S.gpg-agent:0:1
Key = DESKTOP_SESSION, Value = pop
Key = USER, Value = evan
Key = XDG_CONFIG_HOME, Value = /home/evan/.var/app/org.eclipse.Java/config
Key = XDG_MENU_PREFIX, Value = gnome-
Key = GIO_LAUNCHED_DESKTOP_FILE_PID, Value = 5636
Key = QT_ACCESSIBILITY, Value = 1
Key = WINDOWPATH, Value = 2
Key = LC_NUMERIC, Value = en_US.UTF-8
Key = GJS_DEBUG_OUTPUT, Value = stderr
Key = SSH_AUTH_SOCK, Value = /run/user/1000/keyring/ssh
Key = GNOME_SHELL_SESSION_MODE, Value = pop
Key = XDG_RUNTIME_DIR, Value = /run/user/1000

正如评论所证实的那样,我的 ProcessBuilder 确实在不同的目录中查找。我 运行 一个 Linux 的发行版叫做 Pop_OS!它的应用程序商店有 Eclipse 作为 flatpak 可用。

作为一项安全功能,Flatpak 沙盒应用程序本身,将它们降级到它们自己的文件系统部分,而正是这种限制导致了我的问题。

我卸载了 Eclipse 的 Flatpak 版本,并使用他们网站上的 eclipse 安装程序重新安装了它。在我这样做之后,问题就解决了。我能够 运行 我的脚本并且不再有“找不到命令”的问题。