title: Reading output with telnetlib in realtime
body: <p>I'm using Python's telnetlib to telnet to some machine and executing few commands and I want to get the output of these commands.</p>
  
  <p>So, what the current scenario is -</p>
  
  <pre><code>tn = telnetlib.Telnet(HOST)
  tn.read_until("login: ")
  tn.write(user + "\n")
  if password:
      tn.read_until("Password: ")
      tn.write(password + "\n")
  
  tn.write("command1")
  tn.write("command2")
  tn.write("command3")
  tn.write("command4")
  tn.write("exit\n")
  
  sess_op = tn.read_all()
  print sess_op
  #here I get the whole output
  </code></pre>
  
  <p>Now, I can get all the consolidated output in sess_op.</p>
  
  <p>But, what I want is to get the output of command1 immediately after its execution and before the execution of command2 as if I'm working in the shell of the other machine, as shown here -</p>
  
  <pre><code>tn = telnetlib.Telnet(HOST)
  tn.read_until("login: ")
  tn.write(user + "\n")
  if password:
      tn.read_until("Password: ")
      tn.write(password + "\n")
  
  tn.write("command1")
  #here I want to get the output for command1
  tn.write("command2")
  #here I want to get the output for command2
  tn.write("command3")
  tn.write("command4")
  tn.write("exit\n")
  
  sess_op = tn.read_all()
  print sess_op
  </code></pre>