an expect-like golang library to automate control of terminal or console based programs.
Switch branches/tags
Nothing to show
Clone or download
coryb Merge pull request #9 from coryb/report-matchers
send all missed expect matchers to the observers when there is an error.
Latest commit 9d1f448 Sep 28, 2018
Permalink
Failed to load latest commit information.
vendor/github.com/kr/pty Add expect implementation and tests May 14, 2018
.travis.yml Fix OSX io.ErrNoProgress error when using longer Timeout. Aug 14, 2018
Gopkg.lock Add expect implementation and tests May 14, 2018
Gopkg.toml Add expect implementation and tests May 14, 2018
LICENSE Add expect implementation and tests May 14, 2018
OSSMETADATA Add expect implementation and tests May 14, 2018
README.md Heavy modification of Console implementation to correctly provide a pty Jun 7, 2018
console.go send all missed expect matchers to the observers when there is an error. Sep 28, 2018
doc.go Add ExpectOpts to match Regexp, Strings and fix EOF runes Jun 13, 2018
expect.go send all missed expect matchers to the observers when there is an error. Sep 28, 2018
expect_opt.go Add expect.All to match a unordered group of expect opts Sep 27, 2018
expect_opt_test.go Add expect.All to match a unordered group of expect opts Sep 27, 2018
expect_test.go send all missed expect matchers to the observers when there is an error. Sep 28, 2018
passthrough_pipe.go Fix OSX io.ErrNoProgress error when using longer Timeout. Aug 14, 2018
passthrough_pipe_test.go Fix OSX io.ErrNoProgress error when using longer Timeout. Aug 14, 2018
reader_lease.go Refactor (*ReaderLease).Reader to (*ReaderLease).NewReader Jun 26, 2018
reader_lease_test.go Refactor (*ReaderLease).Reader to (*ReaderLease).NewReader Jun 26, 2018
test_log.go Fix doc license headers Jun 15, 2018

README.md

go-expect

Build Status GoDoc NetflixOSS Lifecycle

Package expect provides an expect-like interface to automate control of applications. It is unlike expect in that it does not spawn or manage process lifecycle. This package only focuses on expecting output and sending input through it's psuedoterminal.

Usage

package main

import (
	"log"
	"os"
	"os/exec"
	"time"

	expect "github.com/Netflix/go-expect"
)

func main() {
	c, err := expect.NewConsole(expect.WithStdout(os.Stdout))
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	cmd := exec.Command("vi")
	cmd.Stdin = c.Tty()
	cmd.Stdout = c.Tty()
	cmd.Stderr = c.Tty()

	go func() {
		c.ExpectEOF()
	}()

	err = cmd.Start()
	if err != nil {
		log.Fatal(err)
	}

	time.Sleep(time.Second)
	c.Send("iHello world\x1b")
	time.Sleep(time.Second)
	c.Send("dd")
	time.Sleep(time.Second)
	c.SendLine(":q!")

	err = cmd.Wait()
	if err != nil {
		log.Fatal(err)
	}
}