今天闲着无事,我之前的一些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.csdn.net/clhon