GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Netflix/go-expect: an expect-like golang library to automate control of terminal or console based programs.

BranchesTags
Open more actions menu

Latest commit

 

History

64 Commits
64 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
OSSMETADATA
OSSMETADATA
 
 
README.md
README.md
 
 
console.go
console.go
 
 
doc.go
doc.go
 
 
expect.go
expect.go
 
 
expect_opt.go
expect_opt.go
 
 
expect_opt_test.go
expect_opt_test.go
 
 
expect_test.go
expect_test.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
passthrough_pipe.go
passthrough_pipe.go
 
 
passthrough_pipe_test.go
passthrough_pipe_test.go
 
 
reader_lease.go
reader_lease.go
 
 
reader_lease_test.go
reader_lease_test.go
 
 
test_log.go
test_log.go
 
 

Repository files navigation

go-expect

Go 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 pseudoterminal.

Usage

os.Exec example

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

golang.org/x/crypto/ssh/terminal example

package main

import (
	"fmt"

	"golang.org/x/crypto/ssh/terminal"

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

func getPassword(fd int) string {
	bytePassword, _ := terminal.ReadPassword(fd)

	return string(bytePassword)
}

func main() {
	c, _ := expect.NewConsole()

	defer c.Close()

	donec := make(chan struct{})
	go func() {
		defer close(donec)
		c.SendLine("hunter2")
	}()

	echoText := getPassword(int(c.Tty().Fd()))

	<-donec

	fmt.Printf("\nPassword from stdin: %s", echoText)
}

About

an expect-like golang library to automate control of terminal or console based programs.

Topics

automationcliexpect

Resources

Readme
Apache-2.0 license
Activity
Custom properties

Stars

478 stars

Watchers

301 watching

Forks

74 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.