Posted to tcl by aspect at Sun Jan 19 16:10:07 GMT 2014view raw
- foreach {0r 0w} [chan pipe] break
- foreach {1r 1w} [chan pipe] break
- foreach {2r 2w} [chan pipe] break
- fconfigure stdin -blocking no
- fconfigure $1r -blocking no
- fconfigure $2r -blocking no
- fconfigure $0w -buffering none
- set cmd {grep-v {error}}
- fileevent stdin readable [list {*}$cmd stdin $0w]
- fileevent $1r readable [list {*}$cmd $1r stdout]
- fileevent $2r readable [list {*}$cmd $2r stderr]
- proc cat {in out {cond {}}} {
- set s [read $in]
- if {$s ne {}} {
- if {$cond eq {} || [uplevel 1 $cond [list $s]]} {
- puts -nonewline $out $s
- }
- } elseif {[eof $in]} {
- incr ::eof
- }
- }
- proc not {args} {expr ![uplevel 1 $args]}
- proc grep {s in out} {cat $in $out [list regexp $s]}
- proc grep-v {s in out} {cat $in $out [list not regexp $s]}
- exec {*}$argv <@$0r >@$1w 2>@$2w &
- vwait eof