本文整理汇总了Golang中golang.org/x/crypto/ssh.Session.Stdin方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.Stdin方法的具体用法?Golang Session.Stdin怎么用?Golang Session.Stdin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/crypto/ssh.Session
的用法示例。
在下文中一共展示了Session.Stdin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: prepareCommand
func prepareCommand(session *ssh.Session, cmd *command) error {
for _, env := range cmd.Env {
variable := strings.Split(env, "=")
if len(variable) != 2 {
continue
}
if err := session.Setenv(variable[0], variable[1]); err != nil {
return err
}
}
if cmd.Stdout == nil {
session.Stdout = &cmd.stdout
} else {
session.Stdout = cmd.Stdout
}
if cmd.Stdin != nil {
session.Stdin = cmd.Stdin
}
if cmd.Stderr == nil {
session.Stderr = &cmd.stderr
} else {
session.Stderr = cmd.Stderr
}
return nil
}
示例2: NewSSHClientSession
//NewSSHClientSession creates a new ssh session instance
func NewSSHClientSession(s *ssh.Session, in io.Reader) *SSHClientSession {
out := new(bytes.Buffer)
err := new(bytes.Buffer)
s.Stdin = in
s.Stdout = out
s.Stderr = err
return &SSHClientSession{s, in, out, err}
}
示例3:
BeforeEach(func() {
err := session.Run("true")
Expect(err).NotTo(HaveOccurred())
})
It("uses the shell locator to find the default shell path", func() {
Expect(shellLocator.ShellPathCallCount()).To(Equal(1))
cmd := runner.StartArgsForCall(0)
Expect(cmd.Path).To(Equal("/bin/sh"))
})
})
Context("when stdin is provided by the client", func() {
BeforeEach(func() {
session.Stdin = strings.NewReader("Hello")
})
It("can use the session to execute a command that reads it", func() {
result, err := session.Output("cat")
Expect(err).NotTo(HaveOccurred())
Expect(string(result)).To(Equal("Hello"))
})
})
Context("when the command exits with a non-zero value", func() {
It("it preserve the exit code", func() {
err := session.Run("exit 3")
Expect(err).To(HaveOccurred())
exitErr, ok := err.(*ssh.ExitError)