1

I am trying to learn executing command on remote system using python paramiko code. I am receiving partial output of length 12519 characters. How can I get complete result of length 12550 or more?

Here is the code, this is a code taken from a different site in internet only

def _run_poll(self, session, timeout, input_data):
    '''
    Poll until the command completes.

    @param session     The session.
    @param timeout     The timeout in seconds.
    @param input_data  The input data.
    @returns the output
    '''
    interval = 0.1
    maxseconds = timeout
    maxcount = maxseconds / interval

    # Poll until completion or timeout
    # Note that we cannot directly use the stdout file descriptor
    # because it stalls at 64K bytes (65536).
    input_idx = 0
    timeout_flag = False
    self.info('polling (%d, %d)' % (maxseconds, maxcount))
    start = datetime.datetime.now()
    start_secs = time.mktime(start.timetuple())
    output = ''
    session.setblocking(0)
    while True:
        if session.recv_ready():
            data = session.recv(self.bufsize)
            output += data
            self.info('read %d bytes, total %d' % (len(data), len(output)))
            print('[{}]'.format(output))
            #this prints partial output of 12519 characters

            if session.send_ready():
                # We received a potential prompt.
                # In the future this could be made to work more like
                # pexpect with pattern matching.
                if input_idx < len(input_data):
                    data = input_data[input_idx] + '\n'
                    input_idx += 1
                    self.info('sending input data %d' % (len(data)))
                    session.send(data)

        self.info('session.exit_status_ready() = %s' % (str(session.exit_status_ready())))
        if session.exit_status_ready():
            print('here') #this line is also printed
            break

        # Timeout check
        now = datetime.datetime.now()
        now_secs = time.mktime(now.timetuple())
        et_secs = now_secs - start_secs
        self.info('timeout check %d %d' % (et_secs, maxseconds))
        if et_secs > maxseconds:
            self.info('polling finished - timeout')
            timeout_flag = True
            break
        time.sleep(0.200)

    self.info('polling loop ended')
    if session.recv_ready():
        data = session.recv(self.bufsize)
        output += data
        self.info('read %d bytes, total %d' % (len(data), len(output)))

    self.info('polling finished - %d output bytes' % (len(output)))
    if timeout_flag:
        self.info('appending timeout message')
        output += '\nERROR: timeout after %d seconds\n' % (timeout)
        session.close()

    return output
tintin
  • 23
  • 4
  • I encountered the same problem try this if it can help: http://stackoverflow.com/questions/14643861/paramiko-channel-stucks-when-reading-large-ouput – vipulb Feb 17 '14 at 12:36
  • Tried that one too. It's not yet resolved – tintin Feb 24 '14 at 17:07
  • Check: http://jessenoller.com/blog/2009/02/05/ssh-programming-with-paramiko-completely-different – kenorb May 19 '15 at 12:50

0 Answers0