func (c *Client) run(cmd string) (string, error) {
	if c.debug {
		fmt.Println("Executing:", cmd)
	}

	stdoutB := new(bytes.Buffer)
	session, err := c.sshClient.NewSession()
	if err != nil {
		return "", err
	}

	defer session.Close()

	modes := ssh.TerminalModes{
		ssh.ECHO:          0,     // disable echoing
		ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud
		ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud
	}

	err = session.RequestPty("xterm", 80, 40, modes)
	if err != nil {
		return "", err
	}

	session.Stdout = stdoutB
	in, _ := session.StdinPipe()

	go func(in io.Writer, output *bytes.Buffer) {
		for {
			if output != nil {
				if output.Len() > 0 {
					if bytes.Contains(output.Bytes(), []byte("[sudo] password for ")) {
						_, err = in.Write([]byte(c.password + "\n"))
						if err != nil {
							break
						}
						if c.debug {
							fmt.Println("put the password ---  end .")
						}
						break
					}
				}
			}
		}
	}(in, stdoutB)

	if err := session.Run(cmd); err != nil {
		return "", err
	}

	return stdoutB.String(), nil
}
// runs a command and returns the output
runs a command and returns the output
// runs a command and returns the output
func (c *Client) run(cmd string) (string, error) {
	if c.debug {
		fmt.Println("Executing:", cmd)
	}
	stdoutB := new(bytes.Buffer)
	session, err := c.sshClient.NewSession()
	if err != nil {
		return "", err
	}
	defer session.Close()
	modes := ssh.TerminalModes{
		ssh.ECHO:          0,     
		ssh.TTY_OP_ISPEED: 14400, 
		ssh.TTY_OP_OSPEED: 14400, 
	}
	err = session.RequestPty("xterm", 80, 40, modes)
	if err != nil {
		return "", err
	}
	session.Stdout = stdoutB
	in, _ := session.StdinPipe()
	go func(in io.Writer, output *bytes.Buffer) {
		for {
			if output != nil {
				if output.Len() > 0 {
					if bytes.Contains(output.Bytes(), []byte("[sudo] password for ")) {
						_, err = in.Write([]byte(c.password + "\n"))
						if err != nil {
							break
						}
						if c.debug {
							fmt.Println("put the password ---  end .")
						}
						break
					}
				}
			}
		}
	}(in, stdoutB)
	if err := session.Run(cmd); err != nil {
		return "", err
	}
	return stdoutB.String(), nil
}
func ( c * Client ) run ( cmd string ) ( string , error ) { if c . debug { fmt . Println ( " " , cmd ) } stdoutB := new ( bytes . Buffer ) session , err := c . sshClient . NewSession ( ) if err != nil { return " " , err } defer session . Close ( ) modes := ssh . TerminalModes { ssh . ECHO : 0 , ssh . TTY_OP_ISPEED : 14400 , ssh . TTY_OP_OSPEED : 14400 , } err = session . RequestPty ( " " , 80 , 40 , modes ) if err != nil { return " " , err } session . Stdout = stdoutB in , _ := session . StdinPipe ( ) go func ( in io . Writer , output * bytes . Buffer ) { for { if output != nil { if output . Len ( ) > 0 { if bytes . Contains ( output . Bytes ( ) , [ ] byte ( " " ) ) { _ , err = in . Write ( [ ] byte ( c . password + " \n " ) ) if err != nil { break } if c . debug { fmt . Println ( " " ) } break } } } } } ( in , stdoutB ) if err := session . Run ( cmd ) ; err != nil { return " " , err } return stdoutB . String ( ) , nil }
runs a command and returns the output
runs a command and returns the output
// disable echoing // input speed = 14.4kbaud // output speed = 14.4kbaud