Posted to tcl by aspect at Sat Feb 28 01:08:04 GMT 2015view raw
- set fd [open "|ping csiro.au" r]
- chan configure $fd -blocking 0
- chan event $fd readable [list pong $fd]
- proc pong {fd} {
- set ln [gets $fd]
- if {$ln eq ""} {
- if {[eof $fd]} {
- puts "Ping died!"
- close $fd
- after idle finished
- return
- }
- }
- puts "Pong! $ln"
- }
- after 5000 [list finished $fd]
- proc finished {fd} {
- puts "Killing ping"
- catch {close $fd}
- exit
- }
- vwait forever