I'm trying to programmatically create a telnet session.  Within the
interactive environment, this appears to work very well as server messages
can be saved as strings:

$ python
Python 2.7.1 (r271:86832, Sep  3 2011, 01:32:33)
[GCC 4.2.1 20070719 ] on openbsd5
Type "help", "copyright", "credits" or "license" for more information.
>>> import telnetlib
>>> tn = telnetlib.Telnet('gmail-smtp-in.l.google.com', 25)
>>> s = tn.read_very_eager()
>>> print s
220 mx.google.com ESMTP r70si1582241yhm.54

>>> tn.write("helo\n")
>>> s = tn.read_very_eager()
>>> print s
250 mx.google.com at your service

>>> tn.write("quit\n")
>>> s = tn.read_very_eager()
>>> print s
221 2.0.0 closing connection r70si1582241yhm.54

>>>
$

These server response can then be parsed to determine what commands need to
be provided next.

Yet when I execute the same methods in a script, I am getting nothing in
response:

 $ cat script.py
#!/usr/bin/env python

import telnetlib

if __name__ == '__main__':
    print 'begin'
    tn = telnetlib.Telnet('gmail-smtp-in.l.google.com', 25)
    s = tn.read_very_eager()
    print s
    tn.write("helo\n")
    s = tn.read_very_eager()
    print s
    tn.write("quit\n")
    s = tn.read_very_eager()
    print s
    print 'end'
$ python script.py
begin



end
$

What do I need to do to emulate the IDE environment?  If I am needing to
capture stdout, it isn't readily apparent.

Any insight you can share would be greatly appreciated.

Jim
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to