Re: Pipeline never becomes readable



On Jun 26, 4:57 pm, Alexandre Ferrieux <alexandre.ferri...@xxxxxxxxx>
wrote:
On Jun 26, 10:43 pm, wimaxj <wim...@xxxxxxxxx> wrote:



Hi,

I want to interact with gnuplot in Tcl in the following way:

====================
set a [open "|gnuplot" RDWR];
fconfigure $a -blocking 0;
fileevent $a readable [list show $a];

proc show {ch} {
puts "This is show";
puts [read $ch];

}

# no matter how, the pipeline never becomes readable
puts $a {plot "data.file" using 1:2};
puts $a {help}; # it should print help document
puts $a {some nosense}; # it should print error msg.
=====================

No matter what input I gave, there's no feedback from gnuplot. The
proc. "show" never be called. Anything wrong here?

First, you should make sure your [puts] to the pipe are flushed. For
this, the simplest is to [fconfigure -buffering line] since
interaction with gnuplot is line-oriented.

Second, just in case something interesting is written to stderr by
gnuplot, better route it transparently to tclsh's stderr:

set a [open "|gnuplot 2>@ stderr" RDWR];

Third, in your fileevent you may want to read in line-oriented mode
too with [gets]:

proc show {chan} {
if {[gets $chan line] >= 0} {
puts SHOW:$line
} elseif {[eof $chan]} {
close $chan
}
}

(example stolen to Donal, should normally make it to the manpage
quickly)

-Alex

Hi,

Thank you very much for the suggestion. I forgot to mention that I did
flush the channel whenever I wrote to it. This doesn't help.

But [open "|gnuplot 2>@ stderr" RDWR] really make the feedback from
gnuplot printed on the screen. But it's not from the proc. "show",
because no prefix "SHOW:" showing.

So, the problem remains.
.



Relevant Pages

  • Re: disabling fileevent
    ... proc send { ... puts -nonewline $out $str; ... I am facing a problem with fileevent handling. ... fileevent $sock readable [readUDP $sock] ...
    (comp.lang.tcl)
  • Re: Pipeline never becomes readable
    ... proc show { ... No matter what input I gave, there's no feedback from gnuplot. ... the simplest is to [fconfigure -buffering line] since ... in your fileevent you may want to read in line-oriented mode ...
    (comp.lang.tcl)
  • read on socket hangs
    ... And my channel has 2 PDu's ... proc initiate_request { ... fconfigure $channel -translation binary ... puts "Sent Initiate Request message" ...
    (comp.lang.tcl)
  • Re: Running procs at timed intervals after script has completed
    ... proc every { ... puts -nonewline + ... from within Tcl). ...
    (comp.lang.tcl)
  • Re: Dangerous update command
    ... Say you had a heavy I/O with fileevents and then called ... does a similar thing since it just adds a fileevent when the idle ... True, but most people just use puts to write to a channel, and don't use ... puts -nonewline $chan $data ...
    (comp.lang.tcl)