2012-05-31 79 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

好吧,我已經添加了一個示例;試試這個腳本 –