June 2017
Intermediate to advanced
446 pages
10h 10m
English
In this section, we will look at more Pexpect features that might come in handy when the situation arises.
If you have a slow link to your remote device, the default expect() method timeout is 30 seconds, which you can be increased via the timeout argument:
>>> child.expect('Username', timeout=5)
You can choose to pass the command back to the user using the interact() method. This is useful when you just want to automate certain parts of the initial task:
>>> child.sendline('show version | i V')19>>> child.expect('iosv-1#')0>>> child.beforeb'show version | i VrnCisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.6(2)T, RELEASE SOFTWARE (fc2)rnProcessor board ID 9MM4BI7B0DSWK40KV1IIRrn'>>> child.interact() ...Read now
Unlock full access