具有非常相似的命令调用
cmdDirect := exec.Command("theExecutable")
cmdShell := exec.Command(os.GetEnv("SHELL"), "-c", "theExecutable")
两者具有相同的环境设置
envWithPath := append(os.Environ(), fmt.Sprintf("PATH=/real/existing/path/to/theExecutable/holder:%s", os.GetEnv("PATH")))
cmdDirect.Env = envWithPath
cmdShell.Env = envWithPath
不过,虽然cmdShell
的运行情况和预期一样好,但cmdDirect
失败了
exec: "theExecutable": executable file not found in $PATH
对于所提到的完全相同的环境设置,调用也成功
cmdWhich := exec.Command("which", "theExecutable")
适当地返回/real/existing/path/to/theExecutable/holder/theExecutable
%
那么,造成这种差异的原因可能是什么呢?
另外,这两种方法肯定都有非常相同的$PATH
设置.例如.
exec.Command("env")
exec.Command(os.GetEnv("SHELL"), "-c", "env")
两个输出都是相同的PATH=....
序列吗
THX