telnetlib question

Eddie Corns eddie at holyrood.ed.ac.uk
Fri Apr 5 06:14:31 EST 2002


"NightOwl" <nightowl at uk2.net> writes:

>Hi,

>I would like to be able to read the output of the last command in a telnet
>session, without shutting it down.

>What I would like to do is

>- log in (can do that)
>- cat the contents of a couple of files (while the content <> searchstring)
>- if the search string is found, echo something.

>I managed to log in and cat a file, I managed to do read_all(), however,
>that outputs everything AND it seems like I needed to close the connection
>first. The doc's are not clear at all at this point. What function do I
>need?

>Can somebody give me some example code, or the correct function to read the
>output of the last command (the last cat in my case)?

>I found read_eager(), read_lazy etc, however, the explanation is very
>unclear to me!

Yup, those docs are somewhat on the terse side.

As a suggestion, what I normally use is read_until (prompt) to package up the
output from each command.  It's not so easy if the prompt keeps changing but
as long as there is something you know for sure you can match on (eg stick an
'echo blah' command after the cat).

I can e-mail you some examples if you want.

Eddie



More information about the Python-list mailing list