tree: aff83b290db17186dce47d1dfc5b47f86e0ee314 [path history] [tgz]
  1. .gitignore
  2. License
  3. Makefile
  4. pty_linux.go
  5. README.md
  6. run.go
README.md

pty

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!)

Install

go get github.com/kr/pty

Example

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()
}