Posted to tcl by schelte at Tue Jun 15 21:54:46 GMT 2010view raw
- a.tcl:
- #!/usr/bin/tclsh
- set f [open "|./b.tcl" r+]
- fconfigure $f -buffering line -blocking 0
- fileevent $f readable [list data $f]
- proc data {fd} {
- if {[eof $fd]} {
- puts EOF
- close $fd
- exit
- } elseif {[gets $fd line] != -1} {
- puts $line
- }
- }
- after 12000 puts $f reset
- after 32000 puts $f quit
- vwait forever
- ###############################################################
- b.tcl:
- #!/usr/bin/tclsh
- fileevent stdin readable [list data stdin]
- fconfigure stdin -blocking 0
- fconfigure stdout -buffering line
- proc data {fd} {
- if {[eof $fd]} {
- exit
- } elseif {[gets $fd line]} {
- if {$line eq "quit"} {
- exit
- } elseif {$line eq "reset"} {
- set ::counter 0
- }
- }
- }
- proc output {} {
- puts [incr ::counter]
- after 5000 output
- }
- output
- vwait forever