blob: b56a90120a90368c9af6e06d362671cadf736052 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// +build !windows
package shellwords
import (
"fmt"
"os"
"os/exec"
"strings"
)
func shellRun(line, dir string) (string, error) {
var shell string
if shell = os.Getenv("SHELL"); shell == "" {
shell = "/bin/sh"
}
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
}
|