LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Pexpect output ! (http://www.linuxquestions.org/questions/programming-9/pexpect-output-868744/)

noony123 03-15-2011 12:53 PM

Pexpect output !
 
Hi all.

Today i have download pexpect and started working on it. I want to access my cisco router and capture the output of "show version". So far i am successful in configuring the router. Pls check the script below

import pexpect
import sys

child=pexpect.spawn("ssh cisco@192.168.15.8")
child.expect("Password:")
child.sendline("cisco")
child.expect(".*>")
child.sendline("en")
child.expect("Password:")
child.sendline("cisco")
child.expect(".*#")

child.sendline("conf ter")
child.expect("R1.*#")

child.sendline("int loo 200")
child.logfile = sys.stdout


Now on my router, the configuration was done perfectly. Which means my pexpect script is working fine. But i am not able to get the following

1) I want to capture the output of 'show version' (or any other command) to a file. When i googled, the last bolded line seemed to be the solution but its not working. When i run the script, it simply runs and then i get the prompt again, no output of show version :-(

Pls someone guide me

ntubski 03-16-2011 11:31 PM

I've never used pexpect, but I would guess that you need to set the logfile before running the commands.


All times are GMT -5. The time now is 09:44 AM.