Re: Pipeline never becomes readable
- From: Alexandre Ferrieux <alexandre.ferrieux@xxxxxxxxx>
- Date: Thu, 26 Jun 2008 14:37:28 -0700 (PDT)
On Jun 26, 11:22 pm, koffee <luke...@xxxxxxxxx> wrote:
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.- Hide quoted text -
- Show quoted text -
Then, it must be that gnuplot itself is omitting to flush its stdout,
because it doesn't expect to be spawn behind pipes. Don't know it
enough, maybe there's a technique to make it flush after each line too
(not obvious from the manpage at least)...
Otherwise, you could use the 'nobuf' program from the 'pty' unix
package, to cheat and make gnuplot (stdio in fact) believe it is
writing to a terminal and flush accrodingly.
-Alex
.
- Follow-Ups:
- Re: Pipeline never becomes readable
- From: Alexandre Ferrieux
- Re: Pipeline never becomes readable
- References:
- Pipeline never becomes readable
- From: wimaxj
- Re: Pipeline never becomes readable
- From: Alexandre Ferrieux
- Re: Pipeline never becomes readable
- From: koffee
- Pipeline never becomes readable
- Prev by Date: Re: Pipeline never becomes readable
- Next by Date: Re: Pipeline never becomes readable
- Previous by thread: Re: Pipeline never becomes readable
- Next by thread: Re: Pipeline never becomes readable
- Index(es):
Relevant Pages
|