1.在执行expect('OPR>','show‘)之后,它会变成无限的意思,它继续运行。
from fabric.api import *
from fabric.context_managers import settings
from ilogue.fexpect import expect, expecting, run
prompts = []
prompts += expect('Username:','kirti')
prompts += expect('Password:','kirti')
prompts += expect('OPR>','show users')
prompts +=expect('OPR>','exit')
env.password = "kirti@123"
with cd('/home/kirti/opr'):
with expecting(prompts):
run('./kirti', combine_stderr=False)发布于 2017-12-09 19:51:44
Fabric >= 1.9允许同时在一个with子句中处理多个提示:您只需要使用Fabric的settings函数,并向它提供一个dict;键将是问题,而值将是答案。在您的例子中,它将看起来像:
with settings(prompts={'Username:':'admin',
'Password:':'admin',
'OPR>':'show alef-users',
'OPR>':'exit'}):
run('./go_opr_cli', combine_stderr=False)我的回答是受那一节的织物官方文档的启发。它对我非常有用,但是在编写dict键时,请确保在命令行中尊重问题的最后一个字符和光标之间的空格数,否则就会失败。
最后一个提示符是'OPR>‘。如果您在常规Linux中看到'OPR>‘和光标之间有一个空格,那么键应该是'OPR>’。
https://stackoverflow.com/questions/47448384
复制相似问题