This subject was spoken many times and there is a lot of example on SO and the wiki, but I do not understand what's going on... in my case.
If I'm using exec {*}$mycmd &
, my lines display in real time on my console and it is what I want , but I don't catch them , so I took an another approach and I used open |$mycmd r
but my lines display at the end of command.
% set mycmd [list $exe $journal -args {*}$args 2>c:/temp/error.txt]
% exec {*}$mycmd &
my line display in real time
my line display in real time
my line display in real time
...
...
...
%
my code with pipeline
: Fileevent example
set in [open |$mycmd r]
fconfigure $in -blocking 0
fileevent $in readable [list handleFileEvent $in]
vwait ::forever
proc closePipe {f} {
fconfigure $f -blocking true
if {[catch {close $f} err]} {
puts stderr $err
set ::forever 1
} else {
set ::forever 1
}
}
proc handleFileEvent {f} {
set status [catch { gets $f line } result]
if { $status != 0 } {
puts stderr $result
closePipe $f
} elseif { $result >= 0 } {
puts stdout $line
} elseif { [eof $f] } {
closePipe $f
} elseif { [fblocked $f] } {
puts stdout $line
}
}