本文整理汇总了Golang中golang.org/x/crypto/ssh.Session.CombinedOutput方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.CombinedOutput方法的具体用法?Golang Session.CombinedOutput怎么用?Golang Session.CombinedOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/crypto/ssh.Session
的用法示例。
在下文中一共展示了Session.CombinedOutput方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: execLine
func execLine(session *ssh.Session, cmd string) {
out, err := session.CombinedOutput(cmd)
if err != nil {
// panic(err)
log.Fatal(err.Error())
}
fmt.Println(string(out))
}
示例2: RunCommandWithOutput
// RunCommandWithOutput runs a shell command in a vagrant node and returns it's
// exit status and output
func (n *VagrantNode) RunCommandWithOutput(cmd string) (string, error) {
var (
s *ssh.Session
err error
)
if s, err = n.client.NewSession(); err != nil {
return "", err
}
defer s.Close()
output, err := s.CombinedOutput(newCmdStrWithSource(cmd))
return string(output), err
}
示例3: executeCommand
// Executes a command on an SSH session struct, return an error if there is one
func executeCommand(cmd string, session *ssh.Session) (string, error) {
//Runs CombinedOutput, which takes cmd and returns stderr and stdout of the command
out, err := session.CombinedOutput(cmd)
if err != nil {
return "", err
}
// Convert our output to a string
tmpOut := string(out)
tmpOut = strings.Replace(tmpOut, "\n", "<br>", -1)
// Return a string version of our result
return tmpOut, nil
}
示例4: runCommand
func (client *clientSSH) runCommand(cmd *sshCommand) ([]byte, error) {
var session *ssh.Session
var err error
if session, err = client.newSession(); err != nil {
return []byte{}, err
}
defer session.Close()
if err = client.prepareCommand(session, cmd); err != nil {
return []byte{}, err
}
return session.CombinedOutput(cmd.command)
}