Posted to tcl by mr_calvin at Wed Sep 30 06:48:08 GMT 2020view raw

  1. set pipe [open "|ls"]
  2. chan configure $pipe -blocking 0
  3.  
  4. set handler [list pr {
  5. puts RUN=[incr [namespace current]::RUN]
  6. if {[eof $pr]} {
  7. chan close $pr
  8. set [namespace current]::done 1
  9. } else {
  10. set result [read $pr]
  11. puts RESULT='$result'
  12. }
  13. } [namespace current]]
  14.  
  15. chan event $pipe readable [list apply $handler $pipe]
  16.  
  17. vwait [namespace current]::done