commit | 59dd1489ccd5455720eece7f03c0c42e263fb318 | [log] [tgz] |
---|---|---|
author | Keith Rarick <kr@xph.us> | Wed Feb 01 21:46:36 2012 -0800 |
committer | Keith Rarick <kr@xph.us> | Wed Feb 01 21:46:36 2012 -0800 |
tree | ac7fd593953211a2cce760afe883be3416afc724 | |
parent | 3b1c6581cb38cfd418c2051087c0a56a19d2c23a [diff] |
work with new os/exec
Pty is a Go package for using unix pseudo-terminals.
(Note, there is only a Linux implementation. I'd appreciate a patch for other systems!)
go get github.com/kr/pty
package main
import (
"fmt"
"github.com/kr/pty"
"io"
"os"
"os/exec"
)
func main() {
c := exec.Command("grep", "--color=auto", "bar")
f, err := pty.Start(c)
if err != nil {
panic(err)
}
go func() {
fmt.Fprintln(f, "foo")
fmt.Fprintln(f, "bar")
fmt.Fprintln(f, "baz")
f.Close()
}()
io.Copy(os.Stdout, f)
c.Wait()
}