【问题标题】:Vscode (Mac OS) has different $PATH when running tasksVscode (Mac OS) 在运行任务时有不同的 $PATH
【发布时间】:2021-01-04 08:53:25
【问题描述】:

我正在尝试编写一个自动任务来帮助我构建 go 插件。任务是这样的

        {
            "label": "compile wc.go",
            "type": "shell",
            "command": "go",
            "args": [
                "build",
                "-buildmode=plugin",
                "-gcflags='all=-N -l'",
                "../mrapps/wc.go"
            ],
            "options": {
                "cwd": "${workspaceFolder}/src/main",
            }
        }

当我运行它时,终端显示以下错误:

> Executing task: go build -buildmode=plugin -gcflags='all=-N -l' ../mrapps/wc.go <

/bin/bash: go: command not found
The terminal process "/bin/bash '-c', 'go build -buildmode=plugin -gcflags='all=-N -l' ../mrapps/wc.go'" failed to launch (exit code: 127).

当我运行 go env 命令时,它可以在集成终端上完美运行

(base) XIEs-MacBook-Pro:6.824 j$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
...enter code here

我一直在寻找答案,但没有。

我尝试了另一个任务

        {
            "label": "test",
            "type": "shell",
            "command": "echo $PATH",
            "options": {
                "cwd": "${workspaceFolder}/src/main"
            }
        }

它打印我的 PATH,这与我在 bash 或集成终端中得到的明显不同。

我还尝试按任务打开一个 python 解释器,它产生一个 python 2.7,肯定不是默认的(由哪个 python)。

【问题讨论】:

    标签: go visual-studio-code environment-variables vscode-tasks


    【解决方案1】:

    您可能应该设置Run as login shell,以便导出bash_profile(rc) 中的所有变量。 AFAIK 这里是设置 "terminal.integrated.shellArgs.osx": ["-l"]

    【讨论】:

      【解决方案2】:

      尝试按照@Зелёный 的建议设置terminal.integrated.shellArgs.osx,或者您也可以设置terminal.integrated.automationShell.osx 指向/bin/bash

      【讨论】:

        猜你喜欢
        • 2022-11-18
        • 1970-01-01
        • 2019-11-27
        • 2015-09-23
        • 2015-11-05
        • 2019-10-29
        • 1970-01-01
        • 2011-08-20
        • 1970-01-01
        相关资源
        最近更新 更多