2011-09-29 64 views
2

我試圖在winpexpect中使用plink連接到遠程Linux服務器。我使用下面的代碼:在winpexpect中運行plink

child = winpexpect.winspawn('plink [email protected]') 
child.logfile = sys.stdout 
i = child.expect(['Password:') 
child.expect('Password:') 
child.sendline('password') 

我得到的標準輸出的輸出是:

Using keyboard-interactive authentication. 
Password: password 

Using keyboard-interactive authentication. 
Password: 
Using keyboard-interactive authentication. 
Password: Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    ...in expect_loop 
raise TIMEOUT (str(e) + '\n' + str(self)) 
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking(). 
... 
command: plink 
args: ['plink', '[email protected]'] 
buffer (last 100 chars): yboard-interactive authentication. 
Password: 
Using keyboard-interactive authentication. 
Password: 
before (last 100 chars): yboard-interactive authentication. 
Password: 
Using keyboard-interactive authentication. 
Password: 
after: <class 'pexpect.TIMEOUT'> 
... 

等效代碼在Pexpect的Linux下(與Pexpect的更換winpexpect模塊和砰砰通話與ssh),所以我知道expect()匹配是正確的。它看起來像winpexpect正在寫入屏幕,並且plink不會將其註冊爲正在輸入密碼字段的文本。

任何人都可以在這裏發現問題嗎?

+0

您是否找到解決方案?我嘗試從BitBucket更改winpexpect腳本沒有成功。謝謝,克里斯 – chrissygormley

+0

不幸的是,我沒有找到解決方案。看起來像winpexpect中的一個bug,但我沒有時間去嘗試自己弄清楚。 – Symmetric

回答

0

我遇到了與winpexpect和plink類似的問題。 This question有一個解決方案,爲我工作。連接到我的串行接口的設備在本地回顯事物並令winpexpect困惑。用以下函數代替sendline():

child.send(cmd) 
    child.pexpect(cmd) 
    child.send('\n') 

對於每次調用都爲我修正了它。在目標種子\ n並開始響應之前,child.pexpect(cmd)會消耗本地回顯字符。