2019-03-19 11:21:03 -04:00
|
|
|
// +build !go1.6
|
|
|
|
|
|
|
|
package shellwords
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2019-10-23 09:19:20 -04:00
|
|
|
func shellRun(line, dir string) (string, error) {
|
2019-03-19 11:21:03 -04:00
|
|
|
var b []byte
|
|
|
|
var err error
|
2019-10-23 09:19:20 -04:00
|
|
|
var cmd *exec.Cmd
|
2019-03-19 11:21:03 -04:00
|
|
|
if runtime.GOOS == "windows" {
|
2019-10-23 09:19:20 -04:00
|
|
|
cmd = exec.Command(os.Getenv("COMSPEC"), "/c", line)
|
2019-03-19 11:21:03 -04:00
|
|
|
} else {
|
2019-10-23 09:19:20 -04:00
|
|
|
cmd = exec.Command(os.Getenv("SHELL"), "-c", line)
|
2019-03-19 11:21:03 -04:00
|
|
|
}
|
2019-10-23 09:19:20 -04:00
|
|
|
if dir != "" {
|
|
|
|
cmd.Dir = dir
|
|
|
|
}
|
|
|
|
b, err = cmd.Output()
|
2019-03-19 11:21:03 -04:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(string(b)), nil
|
|
|
|
}
|