Posted to tcl by aspect at Thu Oct 29 22:16:38 GMT 2015view raw

  1.  
  2.  
  3. namespace eval tee {
  4. proc initialize args {info procs}
  5. proc finalize args {}
  6. proc clear args {}
  7. proc flush {x h} {chan flush $x}
  8. proc write {x h data} {
  9. puts -nonewline $x $data
  10. chan flush $x
  11. return $data
  12. }
  13. namespace export *
  14. namespace ensemble create -parameters x
  15. }
  16. namespace eval redir {
  17. proc initialize args {info procs}
  18. proc finalize args {}
  19. proc clear args {}
  20. proc flush {x h} {chan flush $x}
  21. proc write {x h data} {
  22. uplevel 1 $x [list $data]
  23. return ""
  24. }
  25. namespace export *
  26. namespace ensemble create -parameters x
  27. }
  28.  
  29.  
  30. package require Tk
  31. pack [text .t]
  32. set fd [open log.txt w]
  33. chan push stdout [list tee $fd]
  34. chan push stderr [list redir {.t insert end}]
  35.  
  36. puts "Hello world!"
  37. puts stderr "This is not right"
  38.