[BangPypers] problems while using pexpect. pexpect.TIMEOUT always...

Senthil Kumaran orsenthil at gmail.com
Mon Jun 8 19:38:43 CEST 2009

On Mon, Jun 08, 2009 at 10:39:00PM +0530, Gora Mohanty wrote:
> > And here is my pexpect script:
> > 
> > http://paste.pocoo.org/show/121788/
> I am not very familiar with pexpect, but from what I remember
> of Expect, there are a couple of issues here:
> o You should be using p.expect() instead of time.sleep()
> o After issuing a 'fortune' command you should be expecting a
>   shell prompt.
> o You should explicitly close the connection by logging out

Thank you, Gora.
Yes, the main problem was the need to 'explicitly close the connection
by doing a logout'. 

I agree with point 1 too; but I read in some discussion that perhaps
read() was sending request too soon, so I had placed time.sleep() at
various places...  illogically before sendline too.

> Please see http://paste.pocoo.org/show/121800/ where I have used
> 'ls' instead of 'fortune' as I did not have the latter installed.
> The pattern matches anything, i.e., whatever be the shell prompt,
> and child.expect also matches EOF.

Yes, this way worked; Adding child.sendline('logout') before I did
child.read() in the original script also worked.

I got to check with pexpect a little more to see if I can just get the
output of a command only instead of the whole session.

Paramiko, is a good module to with ssh related stuff in python, but
unfortunately that is not pure python, So bundling as an option gets
ruled out.


More information about the BangPypers mailing list