Issue while using Telenet in Python 2.3.3
<p>I have written a script for doing telnet on remote machine. When i use run_command from TelnetController class, the output returned by command is used for some processing purpose, Due to network delay i am getting late response and i have to run that command twice so that it can be saved in buffer . e.g 
<code>
uma = telnetC.run_command1('uma')
uma = telnetC.run_command1('uma')
</code></p>

<p>So basically i have to run command twice. Can you guys help me with this to solve this delay problem.</p>

<p>I am using Python 2.3.3.</p>

<p>Below is the python script </p>

<pre><code>class TelnetController:

"""Connect to remote host with TELNET and issue commands.

@ivar host_name: Host name or IP address
@ivar user_name: User name 
@ivar password: Password
@ivar prompt: Command prompt (or partial string matching the end of the prompt)
@ivar tn: Instance of a telnetlib.Telnet object
"""

def __init__(self, host_name, user_name, password, prompt):
    """

    @param host_name: Host name or IP address
    @param user_name: User name 
    @param password: Password
    @param prompt: Command prompt (or partial string matching the end of the prompt)
    """

    self.host_name = host_name
    self.user_name = user_name
    self.password = password
    self.prompt = prompt
    self.tn = None


def login(self):
    """Connect to a remote host and login.

    """
    self.tn = telnetlib.Telnet(self.host_name)      
    self.tn.read_until('login: ')
    self.tn.write(self.user_name + '\n')
    if self.password:
        self.tn.read_until('assword: ')
        self.tn.write(self.password + '\n')
    self.tn.read_until(':')    
    print "Login to " +self.host_name +" is successful" 


def run_command(self, command):
    """Run a command on the remote host.

    @param command: Unix command
    @return: Command output
    @rtype: String
    """ 
    self.tn.write(command + '\n')
    #print command
    response = self.tn.read_until(self.prompt,300)
    #print response
    #return response
    return self.__strip_output(command, response)

def run_command1(self, command):
    """Run a command on the remote host.

    @param command: Unix command
    @return: Command output
    @rtype: String
    """ 
    self.tn.write(command + '\n')
    #print "command " + command
    response = self.tn.read_until(self.prompt,300)
    #print "response " + response
    #return response
    return response

def logout(self):
    """Close the connection to the remote host.

    """
    self.tn.close()


def run_atomic_command(self, command):
    """Connect to a remote host, login, run a command, and close the connection.

    @param command: Unix command
    @return: Command output
    @rtype: String
    """
    self.login()
    command_output = self.run_command(command)
    self.logout()
    return command_output


def __strip_output(self, command, response):
    """Strip everything from the response except the actual command output.

    @param command: Unix command        
    @param response: Command output
    @return: Stripped output
    @rtype: String
    """
    lines = response.splitlines()
    # if our command was echoed back, remove it from the output
    if command in lines[0]:
        lines.pop(0)
    # remove the last element, which is the prompt being displayed again
    lines.pop()
    # append a newline to each line of output
    lines = [item + '\n' for item in lines]
    # join the list back into a string and return it
    return ''.join(lines)
</code></pre>
