今天闲着无事,我之前的一些Tcl脚本翻出来,以下是一个Tcl事件编程的例子:
set done 0
set count 0
proc Reader {fd} {
global done count
if {[eof $fd]} {
puts "eof $fd"
set done 1
close $fd
} else {
set buf [gets $fd]
if {$buf != "" || 1} {
puts $buf
if {[regexp -nocase -- "^Reply from" $buf]} {
incr count
}
if {$count == 5} {
exit
}
}
}
}
puts "Begin to ping, please waiting......"
set fd [open "|ping 10.11.2.85 -n 20"]
puts $fd
fconfigure $fd -blocking 0
fileevent $fd readable [list Reader $fd]
vwait done
任何形式的转载,请写明出处:
http://blog.youkuaiyun.com/clhon
本文展示了一个使用Tcl进行事件编程的实例,通过监听ping命令的输出来演示如何读取文件描述符上的数据,并在接收到特定消息时触发响应。
3544

被折叠的 条评论
为什么被折叠?



