-
Notifications
You must be signed in to change notification settings - Fork 5
/
localexec.go
56 lines (44 loc) · 1.05 KB
/
localexec.go
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package wsep
import (
"io"
"os/exec"
"syscall"
"golang.org/x/xerrors"
)
// LocalExecer executes command on the local system.
type LocalExecer struct {
// ChildProcessPriority overrides the default niceness of all child processes launch by LocalExecer.
ChildProcessPriority *int
}
func (l *localProcess) Stdin() io.WriteCloser {
return l.stdin
}
func (l *localProcess) Stdout() io.Reader {
return l.stdout
}
func (l *localProcess) Stderr() io.Reader {
return l.stderr
}
func (l *localProcess) Wait() error {
err := l.cmd.Wait()
if exitErr, ok := err.(*exec.ExitError); ok {
return ExitError{
code: exitErr.ExitCode(),
error: exitErr.Error(),
}
}
return err
}
func (l *localProcess) Close() error {
return l.cmd.Process.Signal(syscall.SIGTERM)
}
func (l *localProcess) Pid() int {
return l.cmd.Process.Pid
}
type disabledStdinWriter struct{}
func (w disabledStdinWriter) Close() error {
return nil
}
func (w disabledStdinWriter) Write(_ []byte) (written int, err error) {
return 0, xerrors.Errorf("stdin is not enabled for this command")
}