ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Telnet.read_until(expected[, timeout])
Read until a given string, expected, is encountered or until timeout seconds have passed.
When no match is found, return whatever is available instead, possibly the empty string. Raise EOFError if the connection is closed and no cooked data is available.
Telnet.read_all()
Read all data until EOF; block until connection closed.
Telnet.read_until(expected[, timeout])
Read until a given string, expected, is encountered or until timeout seconds have passed.
When no match is found, return whatever is available instead, possibly the empty string. Raise EOFError if the connection is closed and no cooked data is available.
Telnet.read_all()
Read all data until EOF; block until connection closed.
Hey,
I want it to read whatever is being sent so thought the read_all would be best.
i tried the read_until as a test however didnt work.
$ python telnetTest2.py
Traceback (most recent call last):
File "telnetTest2.py", line 9, in ?
data = tn.read_until("Simon")
File "/usr/lib64/python2.4/telnetlib.py", line 317, in read_until
self.process_rawq()
File "/usr/lib64/python2.4/telnetlib.py", line 488, in process_rawq
self.cookedq = self.cookedq + buf[0]
KeyboardInterrupt
^^^^ i killed once it didnt output.
If i do a debug level i see what it should be doing
This line is telling python to telnet to the site towel.blinkenlights.nl port 23 as a test. It shows a telnet version of star wars written by some guys, one of whom is named 'Simon'
Code:
data=tn.read_until("Simon")
This line says put all data from telnet stream into 'data' variable up to the word 'Simon'
If you ran the program on your telnet destination - and you do not have the word 'Simon' in the output - then it would never stop reading. So take my EXAMPLE and modify it to work for your setup.
This line is telling python to telnet to the site towel.blinkenlights.nl port 23 as a test. It shows a telnet version of star wars written by some guys, one of whom is named 'Simon'
Code:
data=tn.read_until("Simon")
This line says put all data from telnet stream into 'data' variable up to the word 'Simon'
If you ran the program on your telnet destination - and you do not have the word 'Simon' in the output - then it would never stop reading. So take my EXAMPLE and modify it to work for your setup.
Ahhh yes perfect i have it outputting what i want when i use the read_until
only problem i have is from what i understand read_all will read the output regardless, however if i change it to read all i dont output anything
Telnet.read_all()
Read all data until EOF; block until connection closed.
"read_all" will continue reading FOREVER until either an EOF(end of file marker) comes through telnet or the telnet connection closes. Your telnet connection doesn't appear to do either, staying open forever, so "read_all" will continue reading FOREVER without ever going to the next line "print data."
Telnet.read_all()
Read all data until EOF; block until connection closed.
"read_all" will continue reading FOREVER until either an EOF(end of file marker) comes through telnet or the telnet connection closes. Your telnet connection doesn't appear to do either, staying open forever, so "read_all" will continue reading FOREVER without ever going to the next line "print data."
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.