pexpect module

Gianluca Trombetta gianluca.trombetta at tin.it
Tue May 18 07:19:32 EDT 2004


Great!

I've disable the pager with the command "terminal length 0" and now it seem
work very well.
Thank you very much John and thank to all other!

Regards,
Gianluca Trombetta

"John Hazen" <john at hazen.net> ha scritto nel messaggio
news:20040517210708.GA28582 at gate2.hazen.net...
> * Gianluca Trombetta <gianluca.trombetta at tin.it> [2004-05-17 09:10]:
> > But I need to run some cisco commands like "show ip bgp summary", this
> > command print a table and put a "More" by default, if the table is too
big
> > for a single terminal screen.
> > So I need to remove this behavior because if I match the " --More-- "
with
> > expect module i can match only the first one "More", then this the
program
> > crash and receives a timeout.
>
> Why don't you post your code and the traceback you're getting.  I think
> you should be able to expect the "More" multiple times.
>
> Try using expect with a list argument, and detect which one matched.
>
> [untested]
>
> console = pexpect.spawn("whatever_command_you_use")
> # probably other stuff here (enabling, etc.) ...
> console.sendline("sh ip bgp summ")
> # look for more or prompt
> return_index = console.expect([" --More-- ","#"])
> while return_index == 0:
>     console.send(" ")
>     return_index = console.expect([" --More-- ","#"])
> # matched prompt, so now you're good to go.
>
>
> Note, that you may have to save the console.before in the while loop, so
> you don't lose it before you match the prompt.
>
> HTH-
>
> John
>
> P.S. [OT]: The cisco command I use to disable the pager is:
> # terminal length 0
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>







More information about the Python-list mailing list