2016-08-26 72 views
0

我有一個使用ftp服務器的列表。這可以隨時更改循環列表

名單:

set ftp1 "192.168.0.12 -u test,test" 
set ftp2 "192.168.0.13 -u test,test" 
set ftp3 "192.168.0.14 -u test,test" 

和這裏TCL代碼,我想在TCL與所有FTPS看看從列表中不連續exec的,但乘以

set ftp1 "192.168.0.12 -u test,test" 
set ftp2 "192.168.0.13 -u test,test" 
set ftp3 "192.168.0.14 -u test,test" 

proc search {nick host handle channel text} { 
    global ftp1 ftp2 ftp3 
    set text [stripcodes bcru $text] 
    set searchtext [lindex [split $text] 0]; 
    set ftp1 "192.168.0.12 -u test,test" 
    set results [exec sh f.sh $ftp1 $searchtext] 
    foreach elem $results { 
     putnow "PRIVMSG$channel :ftp1 $elem" 
    } 
} 
+0

歡迎來到堆棧溢出,請檢查此鏈接 http://stackoverflow.com/help/dont-ask和此 http://stackoverflow.com/tour瞭解如何發佈一個好問題。 – pedrouan

回答

0

的最簡單的事情就是再寫幾個幫手程序。這些過程應該搜索一個站點,並通過回調將結果返回給您的代碼(因爲我們在此討論異步處理)。

# This is a fairly standard pattern for how to do async reading from a pipeline 
# Only the arguments to [open |[list ...]] can be considered custom... 

proc searchOneHost {hostinfo term callback} { 
    set pipeline [open |[list sh f.sh $hostinfo $term]] 
    fconfigure $pipeline -blocking 0 
    fileevent $pipeline readable [list searchResultHandler $pipeline $callback] 
} 
proc searchResultHandler {pipeline callback} { 
    if {[gets $pipeline line] >= 0} { 
     uplevel "#0" [list {*}$callback $line] 
    } elseif {[eof $pipeline]} { 
     close $pipeline 
    } 
} 

# The rest of this code is modelled on your existing code 

set ftp1 "192.168.0.12 -u test,test" 
set ftp2 "192.168.0.13 -u test,test" 
set ftp3 "192.168.0.14 -u test,test" 

proc search {nick host handle channel text} { 
    set searchtext [lindex [split [stripcodes bcru $text]] 0] 
    foreach v {ftp1 ftp2 ftp3} { 
     upvar "#0" $v ftp 
     searchOneHost $ftp $searchtext [list report $channel $v] 
    } 
} 
proc report {channel name found} { 
    foreach elem $found { 
     putnow "PRIVMSG$channel :$name $elem" 
    } 
} 

我只引用#0來解決這裏的熒光筆問題。

+0

酷,大thx,我今天會測試,關於 – rmounton

+0

大thx工作perferct。 – rmounton