pexpect module

Adrian Casey news at outbacklinux.com
Tue May 18 07:20:12 EDT 2004


Ooops - forgot the search for the prompt :-(
Change the expect line to -:
i=child.expect(['--More--', PROMPT],pexpect.TIMEOUT)

(Assumes PROMPT evaluates to a regular expression matching the cisco
prompt).

Adrian Casey wrote:

> First of all, look up the manual for Cisco's 'show' command.  See if there
> is a way to turn off the paging.  If not, try to fool cisco into thinking
> you have a very large page size on your terminal (e.g. 10,000 lines).
> 
> If this is not possible, you can loop in your python script -:
> 
> while 1:
>         i=child.expect('--More--',pexpect.TIMEOUT)
>         if i==0:
>                 child.sendline(' ')
>         else:
>                 break
> 
> Adrian.
> 
> Gianluca Trombetta wrote:
> 
>> hmmm, i'm not so stupid...:-).
>> The command ls -l | more was an example...i'm not really need to run ls
>> -l
>> | more in an automate program.
>> 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.
>> 
>> Hi
>> Gianluca
>> 
>> 
>> 
>> "Lee Harr" <missive at frontiernet.net> ha scritto nel messaggio
>> news:P9Lpc.5055$xg3.4383 at news01.roc.ny...
>>> On 2004-05-14, Gianluca Trombetta <gianluca.trombetta at tin.it> wrote:
>>> > Someone know pexpect module?
>>> > I've a problem working with it...
>>> >
>>> > I need to run some commands on remote hosts, like ls, df -k etc..All
>> right.
>>> > Although, when i launch a command that have a "more" inside, i don't
>> know
>>> > what i must expect!
>>> > An example:
>>> >
>>> > if i want to run an "ls -l | more" on a remote host, it don't return
>>> > me
>> a
>>> > prompt, but a "-------------More-------------"...thus i don't know how
>> much
>>> > this.
>>> >
>>>
>>>
>>> The only reason I can see for piping the command through more would
>>> be if there were a person sitting there wanting to read the output
>>> before going on to read the next page of output.  That seems counter
>>> to the idea of using pexpect to automate the process. Do you
>>> really need to pipe through more?
>>>
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>




More information about the Python-list mailing list