cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1106
Views
0
Helpful
3
Replies

pexpect parse router output

I've got a couple of expect lines to log onto a cisco router and issue the show arp command. I then exit the router, having stored the data into the variable myARP (myARP=child.before)

When I then try and loop over the object (for lines in myARP: print(lines), the info is displayed 1 character per line
l
i
k
e

t
h
i
s

Apologies as this is probably a very basic question, but why can't I display as it is shown if I issue the command manually? Is it to do with the streaming nature of the telnet connection? How can this be resolved PrepaidCardStatus???

3 Replies 3

Hello,

 

can you post the script ? Most likely it is something related to the terminal length. You can try:

 

expect >

send -- "terminal lengh 0\r"

Seb Rupik
VIP Alumni
VIP Alumni

Hi there,

I looks like the variable myARP is a string and not a list. When you are trying to print each element with a newline, you are in fact printing each character of the string.

 

Share your script, we can debug it.

 

cheers,

Seb.

Jon Marshall
Hall of Fame
Hall of Fame

 

As Seb says it looks like it is treating it as a string so try this with your for loop - 

 

for line in myARP.split('\r\n'):
      print(line)

 

basically you are telling it where the separator is for each line through the loop. 

 

Jon

     

Review Cisco Networking products for a $25 gift card