pipeline with [open r+] problem
Hello,
I am trying to use [open] as pipeline.
In my Tcl Script, the Wiki example:
set channel [open |bc r+]
puts $channel "1234567890 * 987654321"
flush $channel
puts [gets $channel]
works correctly.
But when I try to use my own filter
(which is a Perl script beautifier.pl)
in the same way:
set channel [open |./beautifier.pl r+]
puts $channel $line
flush $channel
puts [gets $channel]
it doesn't work, the Tcl script freezes, I think it can't
read from the channel and is waiting for input.
The filter beautifier.pl should work correctly, because
when I try either:
set channel [open "|./beautifier.pl > out" w]
puts $channel $line
flush $channel
or:
set channel [open |./beautifier.pl < in r]
puts [gets $channel]
I get what I expected, it works correctly.
I can't understand why the pipeline channel works when use
only for reading it's output ([open r])
or only for writing to it ([open w])channel,
but doesn't work
when used it both for reading and writing from Tcl script ([open r+]).
I thought that it could be a problem of synchronization
(the Tcl script may have run faster then the filter)
so I tried:
set channel [open "|./beautifier.pl" r+]
fileevent $channel readable "set TV::done 1"
puts $channel "$line"
flush $channel
vwait TV::done
set bline [gets $channel]
and it seems that the fileevent readable doesn't occur at all.
Perhaps the filter doesn't flush his output (but the "[open r]" version
of pipeline works OK)?
Should I send EOF to the filter so as it flushes his output?
But how to send EOF?
Well, I am pretty confused,
please, where is the problem?
Thanks
Radek