2019-03-19 11:21:03 -04:00
|
|
|
// +build windows,go1.6
|
|
|
|
|
2017-04-17 18:08:24 -04:00
|
|
|
package shellwords
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2019-10-23 09:19:20 -04:00
|
|
|
func shellRun(line, dir string) (string, error) {
|
2017-04-17 18:08:24 -04:00
|
|
|
shell := os.Getenv("COMSPEC")
|
2019-10-23 09:19:20 -04:00
|
|
|
cmd := exec.Command(shell, "/c", line)
|
|
|
|
if dir != "" {
|
|
|
|
cmd.Dir = dir
|
|
|
|
}
|
|
|
|
b, err := cmd.Output()
|
2017-04-17 18:08:24 -04:00
|
|
|
if err != nil {
|
2019-03-19 11:21:03 -04:00
|
|
|
if eerr, ok := err.(*exec.ExitError); ok {
|
|
|
|
b = eerr.Stderr
|
|
|
|
}
|
2017-04-17 18:08:24 -04:00
|
|
|
return "", errors.New(err.Error() + ":" + string(b))
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(string(b)), nil
|
|
|
|
}
|