Posted to tcl by aspect at Thu Oct 29 22:16:38 GMT 2015view raw
- namespace eval tee {
- proc initialize args {info procs}
- proc finalize args {}
- proc clear args {}
- proc flush {x h} {chan flush $x}
- proc write {x h data} {
- puts -nonewline $x $data
- chan flush $x
- return $data
- }
- namespace export *
- namespace ensemble create -parameters x
- }
- namespace eval redir {
- proc initialize args {info procs}
- proc finalize args {}
- proc clear args {}
- proc flush {x h} {chan flush $x}
- proc write {x h data} {
- uplevel 1 $x [list $data]
- return ""
- }
- namespace export *
- namespace ensemble create -parameters x
- }
- package require Tk
- pack [text .t]
- set fd [open log.txt w]
- chan push stdout [list tee $fd]
- chan push stderr [list redir {.t insert end}]
- puts "Hello world!"
- puts stderr "This is not right"