我有一个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中看一下列表中的所有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"
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 :(得分: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
来解决这里的荧光笔。