Running remote curses-like application

Alex new_name at mit.edu
Fri May 25 20:17:20 CEST 2001


> I can log into a remote site using telnetlib.  And start a curses-like
> application.
> 
> But i don't seem to be able to interact with this application to
> automate retrieving some data.  I can't seem to get any response from
> the app.

I've done just what you're describing using telnet lib.  I never got
around to actually pulling useful information out of the connection, but
it certainly gives a response.  Here's the code, for what it's worth:

import telnetlib, sys

connection = telnetlib.Telnet('library.mit.edu')
connection.read_until('login:')
connection.write('library\n')
connection.read_until('Password:')
connection.write('\n')
connection.read_until('or  ?  followed by <ENTER> for Help :')
connection.write('1\n')

output = []
while len(output) < 100:
    output.append(connection.read_some())
    sys.stdout.write(output[-1])
    sys.stdout.flush()

print ''.join(output)

######################################################################

HTH.
Alex.



More information about the Python-list mailing list