Hi all.

This is my first post and i am bit new to python. Pls dont mind if my question is dumb, kindly guide me

I am writing a pexpect script (i am using linux Centos 5.5) to access my cisco router and want to record the output of "show version" command

This is my script

import pexpect
import sys

child = pexpect.spawn("ssh homeuser@")

child.sendline("show version")

Now i can see on my router that i have successfully logged in. But i dont know how to catch the output and save it to a file. I saw several examples like child.logfile = sys.stdout etc but i really dont know how to get it working.

Pls if someone has experience with pexpect, kindly help me out.

Note: I have already cached the ssh keys, so to avoid complexity.

Thanks in advance

Edited by bob_b: n/a

6 Years
Discussion Span
Last Post by griswolf

The pexpect documents (here) say

send(self, s)
This sends a string to the child process. This returns the number of
bytes written. If a log file was set then the data is also written to
the log.

So it appears you can set a logfile... and I'd expect that the logfile can be anything with a 'write' method, so easy enough to use, for instance StringIO. This is all supposition on my part: I've never used pexpect.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.