Re: Pipeline never becomes readable



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
.



Relevant Pages

  • Re: Pipeline never becomes readable
    ... the simplest is to [fconfigure -buffering line] since ... interaction with gnuplot is line-oriented. ... But it's not from the proc. ... Then, it must be that gnuplot itself is omitting to flush its stdout, ...
    (comp.lang.tcl)
  • Re: Pipeline never becomes readable
    ... the simplest is to [fconfigure -buffering line] since ... interaction with gnuplot is line-oriented. ... But it's not from the proc. ... Then, it must be that gnuplot itself is omitting to flush its stdout, ...
    (comp.lang.tcl)
  • Pipeline never becomes readable
    ... proc show { ... puts "This is show"; ... No matter what input I gave, there's no feedback from gnuplot. ...
    (comp.lang.tcl)
  • Re: Pipeline never becomes readable
    ... puts "This is show"; ... the simplest is to [fconfigure -buffering line] since ... in your fileevent you may want to read in line-oriented mode ... proc show { ...
    (comp.lang.tcl)