forked from antonmedv/watch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatch_unix.go
More file actions
39 lines (31 loc) · 687 Bytes
/
watch_unix.go
File metadata and controls
39 lines (31 loc) · 687 Bytes
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
// +build !windows
package main
import (
"bytes"
"io"
"os"
"os/exec"
"syscall"
"github.com/kr/pty"
)
const defaultShell = "bash -cli"
func cmdOutput(cmd *exec.Cmd, buf *bytes.Buffer) error {
ptmx, err := pty.Start(cmd)
if err != nil {
return err
}
err = pty.InheritSize(os.Stdin, ptmx)
if err != nil {
return err
}
_, err = io.Copy(buf, ptmx)
if err != nil {
// Linux kernel return EIO when attempting to read from a master pseudo
// terminal which no longer has an open slave. So ignore error here.
// See https://github.com/kr/pty/issues/21
if pathErr, ok := err.(*os.PathError); !ok || pathErr.Err != syscall.EIO {
return err
}
}
return nil
}