Giter Club home page Giter Club logo

expect's People

Contributors

jamesharr avatar slmint avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

expect's Issues

License unclear

In the absence of an actual license it isn't legally feasible for anyone to use this library. It's some fantastic work and I'd love to evaluate it for a project, but we currently can't.

Is there any chance we could get clarification on the license?

spawn ssh send large/long command got /r(carriage return) and (/b)backspace

when spawn ssh client , send large/long command , expect recv /r and /b

we can:

  • use stty -echo disable input echo , just pick up output , but block on some device
  • resize tty size use github.com/kr/pty.Setsize

has better way? etc syscall.SYS_IOCTL+syscall.ECHO?

test code

func TestExpect_SSH(t *testing.T) {
	var PROMPT = `(?m)[^$]*#` // or (?m)[^$]*$
	exp, err := expect.Spawn(
		"ssh",
		"-F", "/dev/null",
		"-o", "UserKnownHostsFile /dev/null",
		"-o", "StricthostKeyChecking false",
		"localhost",
	)
	if err != nil {
		t.Error("Unexpected error spawning 'ssh'", err)
	}

	defer exp.Close()
	exp.SetLogger(expect.TestLogger(t))
	exp.SetTimeout(time.Second * 15)

	// Login
	exp.Expect(`[Pp]assword:`)
	exp.SendMasked("ban password")
	exp.Send("\n")
	exp.Expect(PROMPT) // Wait for prompt

	time.Sleep(1 * time.Second)

	// tty attr
	exp.SendLn("stty -a")
	match, err := exp.Expect(PROMPT) // Wait for prompt
	t.Logf("stty -a:%s", match.Before)

	// less then column size
	exp.SendLn("echo START_1234567890_1234567890_END")
	match, err = exp.Expect(PROMPT) // Wait for prompt
	t.Logf("long command output:%s", match.Before)

	exp.Send("\n")
	exp.Expect(PROMPT) // Wait for prompt

	// got carriage return 
	exp.SendLn("echo START_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_END")
	match, err = exp.Expect(PROMPT) // Wait for prompt
	t.Logf("long command output:%s", match.Before)

	exp.SetWinSize(10240, 768)

	exp.SendLn("echo START_0987654321_0987654321_END")
	match, err = exp.Expect(PROMPT) // Wait for prompt
	t.Logf("long command output:%s", match.Before)

	exp.Send("\n")
	exp.Expect(PROMPT) // Wait for prompt

	exp.SendLn("echo START_0987654321_0987654321_0987654321_0987654321_0987654321_0987654321_0987654321_0987654321_0987654321_0987654321_0987654321_0987654321_END")
	match, err = exp.Expect(PROMPT) // Wait for prompt
	t.Logf("long command output:%s", match.Before)

	time.Sleep(5 * time.Second)

	// Wait for EOF
	exp.SendLn("exit")
	exp.ExpectEOF()
}

func SetWinSize

func (exp *Expect) SetWinSize(rows, cols uint16) error {
	ws := pty.Winsize{rows, cols, 0, 0}
	return pty.Setsize(exp.pty.(*os.File), &ws)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.