Posted to tcl by schelte at Sat May 28 20:46:00 GMT 2011view raw

  1. set file [lindex $argv 0]
  2.  
  3. proc Exec {command callback} {
  4. set f [open |[linsert $command end 2>@1]]
  5. fconfigure $f -blocking 0
  6. fileevent $f readable [linsert $callback end $f]
  7. }
  8.  
  9. proc WaitForExit {done fd} {
  10. if {[catch {gets $fd line} fail]} {
  11. return -code error $fail
  12. } elseif {[eof $fd]} {
  13. if {[catch {close $fd} fail]} {
  14. return -code error $fail
  15. } else {
  16. set ::forever $done
  17. return 0
  18. }
  19. } {
  20. return 1
  21. }
  22. }
  23.  
  24. Exec [list avisplit -i $file -o base -s 5] [list WaitForExit Done]
  25.  
  26. vwait forever
  27. puts $forever