2016-08-26 74 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