title: Python Pexpect spawn object Flush
body: <p>I have a script where i am creating a spawn object using pexpect.</p>
  
  <p>The code looks like this:</p>
  
  <pre><code>self.rshcmd='rsh 192.X.X.X'
  self.pipe1 = pexpect.spawn(command=self.rshcmd, logfile=sys.stdout,maxread=512)
  </code></pre>
  
  <p>Now after I get into this, I expect for prompt which I get is <code>&gt;</code></p>
  
  <p>And now I become su by sending <code>su</code> and then giving the password. Now my prompt as expected becomes <code>#</code></p>
  
  <p>I have a router connected to this spawned PC (192.X.X.X) which is <code>192.168.1.1</code></p>
  
  <p>I telnet into this router by sending <code>telnet 192.168.1.1</code>. After I am done from this router, I want to get out of the telnet session.</p>
  
  <p>So I send in <code>exit</code> and expect for <code>#</code> as I will get back to the the root of the spawned PC. But what I see is that I am actually getting <code>&lt;</code> as my prompt.</p>
  
  <p>So somehow it is sending "exit" twice . One takes me out from telnet and other one takes me out from being root. I think the pipe is not flushed out and we get he some old stacked commands being sent.</p>
  
  <p>Is there a way i can flush out all the older commands in the pipe?</p>
  
  <p>From the documentation there is a flush function, but it seems to do nothing:</p>
  
  <pre><code>flush(self)
      This does nothing. It is here to support the interface for a
      File-like object.
  </code></pre>