<------------------------------ CODE
FOLLOWS---------------------------------->
proc read_cb {} {
global fd
gets $fd line
.text insert end "$line\n"
}
text .text
button .b -text "Done" -command { global exit_app; set exit_app 1 }
pack .text .b
update
set fd [ open fax1 r ]
fconfigure $fd -blocking 0
fileevent $fd readable read_cb
tkwait variable exit_app
"Gregory M. Messner" <gmes...@4dcomm.com> writes:
> I have been trying to write a little TCL/tk program to tail a log file. It
> sort of works but the read_cb is call continously, what am I doing wrong?
> proc read_cb {} {
> global fd
> gets $fd line
> .text insert end "$line\n"
> }
>
> text .text
> button .b -text "Done" -command { global exit_app; set exit_app 1 }
> pack .text .b
> update
>
> set fd [ open fax1 r ]
> fconfigure $fd -blocking 0
>
> fileevent $fd readable read_cb
> tkwait variable exit_app
End-of-file is a valid fileevent, so your program spins after the last
line in the file.
I doubt (some one correct me here) that there is a clean way to do
this properly in tcl without polling. Here's what I would suggest:
proc read_cb {} {
global fd fd_pos fd_idle
if {[tell $fd] > $fd_pos} {
while {[gets $fd line] > -1} {
.text insert end "$line\n"
}
}
set fd_pos [tell $fd]
set fd_idle [after 1000 read_cb]
}
set fd_pos 0
read_cb
--Multipart_Sun_Mar__9_15:13:51_1997-1
Content-Type: text/plain; charset=US-ASCII
Carl D. Roth <ro...@cse.ucsc.edu> (finger for PGP public key)
--Multipart_Sun_Mar__9_15:13:51_1997-1--
Carl D. Roth wrote:
> "Gregory M. Messner" <gmes...@4dcomm.com> writes:
> but the read_cb is call continously, what am I doing wrong?
> > proc read_cb {} {
> > global fd
> > gets $fd line
> > "$line\n"
> > }
> End-of-file is a valid fileevent, so your program spins after
> the last line in the file.
> I doubt (some one correct me here) that there is a clean way
> to do this properly in tcl without polling.
Here is my standard file event handler,
which tests the eof condition:
proc read_cb {inpipe} {
if [eof $inpipe] {
close $inpipe
} else {
.text insert end "[gets $inpipe]\n"
}
}
fileevent $fd readable [list read_cb $fd]
Hope, that helps
Krischan
--
Christian Krone, Varziner Str. 12, D-12161 Berlin
kris...@cs.tu-berlin.de
http://www.cs.tu-berlin.de/~krischan
proc read_cb {} {
global fd
if {![eof $fd]} {
gets $fd line
.text insert end "$line\n"
}
}
--
Jose L Porcayo email: 10366...@compuserve.com
Consultoria y Metodologia