Posted to tcl by mjanssen at Tue Feb 02 10:29:34 GMT 2021view raw

  1. proc util::exec_tail {args} {
  2. # On platforms with `kill`, we can print the output produced by a
  3. # process while it's running. Uses globals and vwait, so only one
  4. # at a time.
  5. set args [lsearch -all -inline -not -exact $args "-ignorestderr"]
  6.  
  7. set ::done 0
  8. set ::tmp [open "| $args 2>@1"]
  9. chan configure $::tmp -blocking 0 -buffering none
  10. chan event $::tmp readable {
  11. set l [chan read $::tmp]
  12. if {![chan eof $::tmp]} {
  13. puts -nonewline $l
  14. flush stdout
  15. } else {
  16. set ::done 1
  17. }
  18. }
  19. vwait ::done
  20. chan close $::tmp
  21. unset ::done
  22. unset ::tmp
  23. }

Comments

Posted by anticrisis at Tue Feb 02 18:13:06 GMT 2021 [text] [code]

Thank you, open to a pipe is so much cleaner!