【发布时间】:2012-06-01 05:30:52
【问题描述】:
我正在学习如何使用 pexpect,我有一个问题。我正在尝试查找远程服务器的版本号,并根据该版本号选择正确的驱动程序号。我不完全确定我应该如何去做。类似于 getline 函数的东西。让我知道是否有任何我可以使用的功能
【问题讨论】:
标签: pexpect
我正在学习如何使用 pexpect,我有一个问题。我正在尝试查找远程服务器的版本号,并根据该版本号选择正确的驱动程序号。我不完全确定我应该如何去做。类似于 getline 函数的东西。让我知道是否有任何我可以使用的功能
【问题讨论】:
标签: pexpect
子 .before 和 .after 属性分别包含标准输出。在匹配的期望之后。
import pexpect
child = pexpect.spawn('cat /etc/issue')
child.expect('Ubuntu.*')
print(child.after)
哪些命令需要输入?如果是驱动安装,你可以使用fabric & fexpect:
from ilogue.fexpect import expect, expecting, run
output = run('get-system-version')
prompts = []
prompts += expect('Which driver version do you want to install?',output)
with expecting(prompts):
run('install-driver-command')
【讨论】:
cat /etc/issue 并检查版本号(使用正则表达式)。所以我想要的是能够得到cat /etc/issue 的输出我不能使用fabric 或fexpect,因为我是在以前的工作的基础上完成的,这些工作都是在pexpect 中完成的:(