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

set file [lindex $argv 0]

proc Exec {command callback} {
    set f [open |[linsert $command end 2>@1]]
    fconfigure $f -blocking 0
    fileevent $f readable [linsert $callback end $f]
}

proc WaitForExit {done fd} {
    if {[catch {gets $fd line} fail]} {
        return -code error $fail
    } elseif {[eof $fd]} {
        if {[catch {close $fd} fail]} {
            return -code error $fail
        } else {
            set ::forever $done
            return 0
        }
    } {
        return 1
    }
}

Exec [list avisplit -i $file -o base -s 5] [list WaitForExit Done]

vwait forever
puts $forever