You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
buildx/vendor/github.com/mattn/go-shellwords/util_windows.go

30 lines
502 B
Go

// +build windows
package shellwords
import (
"fmt"
"os"
"os/exec"
"strings"
)
func shellRun(line, dir string) (string, error) {
var shell string
if shell = os.Getenv("COMSPEC"); shell == "" {
shell = "cmd"
}
cmd := exec.Command(shell, "/c", line)
if dir != "" {
cmd.Dir = dir
}
b, err := cmd.Output()
if err != nil {
if eerr, ok := err.(*exec.ExitError); ok {
b = eerr.Stderr
}
return "", fmt.Errorf("%s: %w", string(b), err)
}
return strings.TrimSpace(string(b)), nil
}