2012-05-31 81 views
1

我正在学习如何使用pexpect,并且我有一个问题。我正在尝试查找远程服务器的版本号,并根据该版本号选择正确的驱动程序编号。我不完全确定我应该如何去做这件事。 getline函数的一些细节。让我知道是否有我可以使用的任何功能使用pexpect返回信息

回答

2

.before.after属性包含stdout之前resp。在匹配的期望之后。

​​

了命令的要求输入?如果是驱动程序的安装,你可以使用布& 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') 
+0

的想法是做一个'猫的/ etc/issue'和检查版本号(使用正则表达式)。所以我想要的是能够得到'cat/etc/issue'的输出 我无法使用fabric或fexpect,因为我正在构建之前的所有工作都是在pexpect中完成的:( – SP6

+0

好吧,我已经添加了一个示例;试试这个脚本 –