Re: Pipeline never becomes readable
- From: Alexandre Ferrieux <alexandre.ferrieux@xxxxxxxxx>
- Date: Thu, 26 Jun 2008 13:57:10 -0700 (PDT)
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
.
- Follow-Ups:
- Re: Pipeline never becomes readable
- From: koffee
- Re: Pipeline never becomes readable
- References:
- Pipeline never becomes readable
- From: wimaxj
- Pipeline never becomes readable
- Prev by Date: Pipeline never becomes readable
- Next by Date: How to make TCL to show the error stack in interpreted mode?
- Previous by thread: Pipeline never becomes readable
- Next by thread: Re: Pipeline never becomes readable
- Index(es):
Relevant Pages
|