本文整理匯總了Golang中code/google/com/p/go/crypto/ssh.Session.CombinedOutput方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.CombinedOutput方法的具體用法?Golang Session.CombinedOutput怎麽用?Golang Session.CombinedOutput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/google/com/p/go/crypto/ssh.Session
的用法示例。
在下文中一共展示了Session.CombinedOutput方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExecPath
func (c *SSHConn) ExecPath(cmd, path string) (out []byte, err error) {
var session *ssh.Session
session, err = c.client.NewSession()
if err != nil {
log.Fatal("Failed to create session: " + err.Error())
}
defer session.Close()
envVars := ""
if c.env != nil {
for name, value := range c.env {
envVars = envVars + name + "=\"" + value + "\" "
/*
TODO: This should be the proper way to set the environment, but fails for some reason
* Investigate why and possibly send pull-request to maintainer
err = session.Setenv(name, value)
if err != nil {
log.Fatal("Failed to set environment: " + err.Error())
}
*/
}
}
cmd = envVars + cmd
if path != "" {
cmd = "cd " + path + " && " + cmd
}
return session.CombinedOutput(cmd)
}