jamesharr / expect Goto Github PK
View Code? Open in Web Editor NEWGo expect tool
License: Apache License 2.0
Go expect tool
License: Apache License 2.0
Goroutine leak marked in commit e04b9af.
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?
when spawn ssh client , send large/long command , expect recv /r and /b
we can:
stty -echo
disable input echo , just pick up output , but block on some devicehas 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)
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.