util_windows.go 410 B

1234567891011121314151617181920212223
  1. // +build windows,go1.6
  2. package shellwords
  3. import (
  4. "errors"
  5. "os"
  6. "os/exec"
  7. "strings"
  8. )
  9. func shellRun(line string) (string, error) {
  10. shell := os.Getenv("COMSPEC")
  11. b, err := exec.Command(shell, "/c", line).Output()
  12. if err != nil {
  13. if eerr, ok := err.(*exec.ExitError); ok {
  14. b = eerr.Stderr
  15. }
  16. return "", errors.New(err.Error() + ":" + string(b))
  17. }
  18. return strings.TrimSpace(string(b)), nil
  19. }