未验证 提交 55bad26e 编写于 作者: M Mislav Marohnić 提交者: GitHub

Merge pull request #2019 from github/wsl-fix

Fix subcommand execution under WSL
......@@ -55,13 +55,35 @@ func (cmd *Cmd) Success() bool {
// Run runs command with `Exec` on platforms except Windows
// which only supports `Spawn`
func (cmd *Cmd) Run() error {
if runtime.GOOS == "windows" {
if isWindows() {
return cmd.Spawn()
} else {
return cmd.Exec()
}
}
func isWindows() bool {
return runtime.GOOS == "windows" || detectWSL()
}
var detectedWSL bool
var detectedWSLContents string
// https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364
func detectWSL() bool {
if !detectedWSL {
b := make([]byte, 1024)
f, err := os.Open("/proc/version")
if err == nil {
f.Read(b)
f.Close()
detectedWSLContents = string(b)
}
detectedWSL = true
}
return strings.Contains(detectedWSLContents, "Microsoft")
}
// Spawn runs command with spawn(3)
func (cmd *Cmd) Spawn() error {
verboseLog(cmd)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册