1

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
    }
}
Mkn
  • 498
  • 1
  • 3
  • 13
  • stdout may be buffered. Try one of these: `flush stdout` after `puts stdout $line`; or `fconfigure stdout -buffering line` – glenn jackman Apr 29 '18 at 15:13
  • Thanks @glennjackman for the response , but same impact... – Mkn Apr 29 '18 at 16:02
  • Are the procedure definitions really after the `vwait`? Or is that just how you happen to have written the question? – Donal Fellows Apr 29 '18 at 17:23
  • Also, if the subprocess writes directly to `/dev/tty` then you won't trap that with a simple pipeline. Some programs do that… – Donal Fellows Apr 29 '18 at 17:25
  • the procedure definition are before my command , just for my question :) /dev/tty what is this ? – Mkn Apr 29 '18 at 18:09
  • You don't have control of the buffering method used in $mycmd. So what you want is going to be quite difficult. You can try redirecting $mycmd output to a file and then having your Tcl program run a tail on it. But the same issues will be present. – Brad Lanam Apr 29 '18 at 20:54
  • @BradLanam That sort of thing is fixable with `unbuffer`, a simple application of Expect… – Donal Fellows Apr 30 '18 at 13:37
  • ok , @DonalFellows Where i can find documentation or example ? – Mkn Apr 30 '18 at 16:53

0 Answers0