mirror of
https://github.com/Hopiu/micro.git
synced 2026-04-10 09:31:00 +00:00
21 lines
385 B
Go
21 lines
385 B
Go
|
|
package shellwords
|
||
|
|
|
||
|
|
import (
|
||
|
|
"errors"
|
||
|
|
"os"
|
||
|
|
"os/exec"
|
||
|
|
"strings"
|
||
|
|
)
|
||
|
|
|
||
|
|
func shellRun(line string) (string, error) {
|
||
|
|
shell := os.Getenv("COMSPEC")
|
||
|
|
b, err := exec.Command(shell, "/c", line).Output()
|
||
|
|
if err != nil {
|
||
|
|
if eerr, ok := err.(*exec.ExitError); ok {
|
||
|
|
b = eerr.Stderr
|
||
|
|
}
|
||
|
|
return "", errors.New(err.Error() + ":" + string(b))
|
||
|
|
}
|
||
|
|
return strings.TrimSpace(string(b)), nil
|
||
|
|
}
|