2014-02-20 30 views
0

我使用plink並希望從Windows連接服務器。我已經創建了一個文本小部件.l1來查看durign連接上發生了什麼。通常,當我使用這個:如何使用plink並同時期待

catch {exec plink.exe -ssh myserver} res 
.l1 insert 1.0 $res 

我收到一個.L1文本組件:「密碼:」,這意味着砰砰的作品,它與服務器的連接,並問我密碼。

當我使用的菌種到位EXEC的:

catch {spawn plink.exe -ssh myserver} res 
expect "password: " 
.l1 insert 1.0 $res 
exp_send "exit" 

我收到了一些隨機數字像1482或4584.爲什麼它不工作?

+0

這是砰砰進程的進程ID。你想展示什麼? –

+0

我想確保plink正在工作,並期望在此階段做出很好的反應。通常plink正在後臺工作,我什麼都看不到。爲什麼它會返回我的ID進程而不是迴應 - 密碼問題? – lucas

回答

1

期待着記住它所看到的。我強烈推薦閱讀「Exploring Expect」書。

像這樣(未經)應該有所幫助:

spawn plink.exe -ssh myserver 
expect "password: " 
.l1 insert 1.0 $expect_out(buffer) 
exp_send "password\r" 
expect "my_shell_prompt$ " 
.l1 insert end $expect_out(buffer) 
... etc