Posted to tcl by aspect at Sun May 31 03:25:08 GMT 2015view raw

  1. #!/usr/bin/tclsh
  2.  
  3. proc multitail {args} {
  4. foreach fn $args {
  5. set chan [open "|tail -f $fn" r]
  6. fconfigure $chan -blocking 0
  7. fileevent $chan readable [list readable $fn $chan]
  8. }
  9. }
  10.  
  11. proc readable {fn chan} {
  12. if {[gets $chan line] <= 0} {
  13. if {[eof $chan]} {
  14. puts "EOF on $fn"
  15. close $chan
  16. }
  17. } else {
  18. puts "$fn:$line"
  19. }
  20. }
  21.  
  22. exec touch a.txt b.txt
  23. multitail a.txt b.txt
  24.  
  25. vwait forever
  26.