func (config *Config) executeCommand(s *ssh.Session, cmd string, sudo bool) ([]byte, error) { if s.Stdout != nil { return nil, errors.New("ssh: Stdout already set") } if s.Stderr != nil { return nil, errors.New("ssh: Stderr already set") } b := newSingleWriterReader() s.Stdout = &b s.Stderr = &b done := make(chan bool) if sudo { stdInWriter, err := s.StdinPipe() if err != nil { if config.AbortOnError == true { log.Fatalf("%s", err) } return nil, err } go config.injectSudoPasswordIfNecessary(done, &b, stdInWriter) } err := s.Run(cmd) close(done) return b.Bytes(), err }
func (sshTransport *SSHTransport) execCmd(session *ssh.Session, cmd string) (*bytes.Buffer, error) { var b bytes.Buffer modes := ssh.TerminalModes{ ECHO: 0, TTY_OP_ISPEED: 14400, TTY_OP_OSPEED: 14400, } if err := session.RequestPty("xterm", 80, 40, modes); err != nil { log.Fatalf("request for pseudo terminal failed: " + err.Error()) } session.Stdout = &b session.Stderr = &b return &b, session.Run(cmd) }