Posted to tcl by kostix at Sat Nov 07 17:52:49 GMT 2009view raw

  1. set active 0
  2.  
  3. proc Spawn what {
  4. variable active
  5. set fd [open "| $what &"]
  6. fileevent $fd readable [list ReadLine $fd]
  7. incr active
  8. }
  9.  
  10. proc ReadLine fd {
  11. if {[gets $fd line] < 0} {
  12. incr active -1
  13. if {$active == 0} {
  14. set ::done 1
  15. }
  16. }
  17. }
  18.  
  19. Spawn my_program
  20. # repeat N times
  21.  
  22. vwait done