pexpect - logging input AND output

Chris Angelico rosuav at gmail.com
Thu Aug 14 05:14:51 EDT 2014


On Thu, Aug 14, 2014 at 6:59 PM,  <sj.constantine at gmail.com> wrote:
> i have a script running a few commands on a network device. i can't seem to figure out how to log both the input and output of what the pexpect script initiates and responds to.
>
> child = pexpect.spawn ('telnet '+ ip)

If that's not working for you, would it be easier instead to simply
open a socket connection to port 23 on that IP address? Then you'd
just write to the socket (and log what you write) and read from it
(and log that). It's possible you'll see some TELNET or ANSI codes
coming back, but I expect you won't have to send any of them.

ChrisA



More information about the Python-list mailing list