本文整理汇总了Golang中golang.org/x/crypto/ssh.Session.Output方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.Output方法的具体用法?Golang Session.Output怎么用?Golang Session.Output使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/crypto/ssh.Session
的用法示例。
在下文中一共展示了Session.Output方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunCommandAndWait
func (client *SSHClient) RunCommandAndWait(cmd *SSHCommand) ([]byte, error) {
var (
session *ssh.Session
err error
baData []byte
)
if session, err = client.newSession(); err != nil {
return nil, err
}
defer session.Close()
baData, err = session.Output(cmd.Path)
return baData, err
}
示例2:
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)
Expect(ok).To(BeTrue())
Expect(exitErr.ExitStatus()).To(Equal(3))
})
})