def run(cmd)
      ret = {
        :exit_status => 0,
        :stdout      => "",
        :stderr      => ""
      }

      port = ssh_args[:port]

      Net::SSH.start(host, username, ssh_args) do |ssh|
        ssh.open_channel do |ch|
          if stdin
            ch.send_data(stdin)
            ch.eof!
          end

          if require_pty
            ch.request_pty do |ch, success|
              unless success
                raise "The use_sudo setting requires a PTY, and your SSH is rejecting our attempt to get one."
              end
            end
          end

          ch.on_open_failed do |ch, code, desc|
            raise "Connection Error to #{username}@#{host}: #{desc}"
          end

          ch.exec(cmd) do |ch, success|
            unless success
              raise "Could not execute command '#{cmd}' on #{username}@#{host}"
            end

            if merge_output
              ch.on_data do |ch, data|
                log(host, port, data)
                ret[:stdout] << data
              end

              ch.on_extended_data do |ch, type, data|
                if type == 1
                  log(host, port, data)
                  ret[:stdout] << data
                end
              end
            else
              ch.on_data do |ch, data|
                log(host, port, data)
                ret[:stdout] << data
              end

              ch.on_extended_data do |ch, type, data|
                ret[:stderr] << data if type == 1
              end
            end

            ch.on_request("exit-status") do |ch, data|
              ret[:exit_status] = data.read_long
            end
          end
        end

        ssh.loop
      end

      return ret
    end
def run(cmd)
      ret = {
        :exit_status => 0,
        :stdout      => "",
        :stderr      => ""
      }

      port = ssh_args[:port]

      Net::SSH.start(host, username, ssh_args) do |ssh|
        ssh.open_channel do |ch|
          if stdin
            ch.send_data(stdin)
            ch.eof!
          end

          if require_pty
            ch.request_pty do |ch, success|
              unless success
                raise "The use_sudo setting requires a PTY, and your SSH is rejecting our attempt to get one."
              end
            end
          end

          ch.on_open_failed do |ch, code, desc|
            raise "Connection Error to #{username}@#{host}: #{desc}"
          end

          ch.exec(cmd) do |ch, success|
            unless success
              raise "Could not execute command '#{cmd}' on #{username}@#{host}"
            end

            if merge_output
              ch.on_data do |ch, data|
                log(host, port, data)
                ret[:stdout] << data
              end

              ch.on_extended_data do |ch, type, data|
                if type == 1
                  log(host, port, data)
                  ret[:stdout] << data
                end
              end
            else
              ch.on_data do |ch, data|
                log(host, port, data)
                ret[:stdout] << data
              end

              ch.on_extended_data do |ch, type, data|
                ret[:stderr] << data if type == 1
              end
            end

            ch.on_request("exit-status") do |ch, data|
              ret[:exit_status] = data.read_long
            end
          end
        end

        ssh.loop
      end

      return ret
    end
Run the command on the remote host.

 Return value is a hash of symbol -> value, where symbol might be:

 * :stdout -- the standard output of the run. if #merge_output is
   supplied, this will be all the output. Will be an empty string by
   default.
 * :stderr -- standard error. Will be an empty string by default.
 * :exit_status -- the exit status. Will be zero by default.