2012-07-30 70 views
1

$ remote-> waitfor('/ Logoff /');Perl telnet登錄

我得到的錯誤有時會說服務器不可用時模式匹配超時。我想處理這個錯誤。每當發生這種錯誤,我想讓我的腳本睡1分鐘,並嘗試重新登錄。

我已經tryied是這樣的:

if($remote->waitfor('/Logoff/')) 
    { 
    #proceed login perform intended operations. 
    } 
    else 
    { 
     sleep(60);#control is not coming here. returning pattern match timed-out error. 
    } 
+0

Aaaaand,當你嘗試它時發生了什麼? – 2012-07-30 07:43:24

回答

2

最「網::遠程登錄」的方法處理錯誤是由「errmode」選項中定義的方法。

這當然包括waitfor方法和超時錯誤。 默認的「errmode」行爲是「死」,這意味着你的waitfor調用將不會返回任何地方,並且無處不在。

爲了有一個值來檢查,你需要設置「errmode」到「回報」:

if($remote->waitfor(-match => '/Logoff/', -errmode => 'return')) 
    { 
    #proceed login perform intended operations. 
    } 
    else 
    { 
     sleep(60); #returning pattern match timed-out error (or something else). 
    } 

注意:如您指定其他選項waitfor,你需要設置匹配模式通過「匹配」選項。

+0

優秀。它的工作很好,謝謝你的快速回答。偉大的工作繼續下去。再次感謝你。 – Mujeeb 2012-07-30 08:56:23

+0

並快速投票或回答接受? – Ouki 2012-07-30 19:39:43