Phillip,
Here's _a_ way to do what you've asked for.
I use a fileevent on a tail -f, rather than a fileevent on
the file--this uses a lot less cpu. Lot less. Did I say
a lot less? I almost got lynched trying it the other way.
Here's a skeleton, you'll have to do a cmd-line break to
kill it, and then confirm that the spawned tail died. I
don't remember how well Solaris does cleaning up orphaned
processes--and the tail is truly orphaned when this app
dies. Of course you could write code to keep track of the
tail's PID and then make a global key binding to <Control-C>
or something that calls a procedure that kills the stored
PID and then exits a bit more gracefully.
Hope this gets you somewhere!
--jim
8<------------------
#!/usr/bin/wish
proc got_new_data {filehandle} {
uplevel 0 {.text insert end [format "%s\n" [gets $filehandle]]}
}
#
# The rest of the procedures, etc.
#
# A widget to put the text in
text .text
pack .text -expand 1 -fill both -side top
set filename "/var/log/messages"
# Note n is the number of initial lines you asked for
set n 3
# Get the file handle
# I might have been format-happy when I wrote this
set pipe_cmd [format "|tail -f -%s %s" $n $filename]
set in_handle [open $pipe_cmd]
fconfigure $in_handle -blocking 0
# Get those first n lines
for {set i 1} {$i < $n} {incr i} {
got_new_data $in_handle
}
# Set the fileevent
fileevent $in_handle readable [list got_new_data $in_handle]
8<------------------
------------------------
From: Phillip Mau <[EMAIL PROTECTED]>
Subject: [vtcl] tail -f
Date: Thu, 29 Jan 1998 12:16:57 -0500 (EST)
To: [EMAIL PROTECTED]
I am trying to output a tail -f of the /var/log/messages (Sun-Solaris)
into some type of Tcl console.
Would this be the way to do it, or what would anyone else recommend.
My goal is to have some type of dynamic console display of the message
log, and then work on excluduing information that I don't want outputs.
We would like to somehow use Tcl to create this output for a console that
I want to make up using Tcl for use in conjunction with Gauntlet Firewall
software.
Checkpoint Firewall-1 has a nice console to see interactively the messages
being generated, and it also highlights certain Alerts.
Perhaps it will be possible to create such an interface with tcl?
Any input would be appreciated.
Thanks.
Phillip Mau
---------------------------------------------------------------------------
To unsubscribe from the Visual Tcl mailing list, please send a message
to [EMAIL PROTECTED] with "unsubscribe vtcl [EMAIL PROTECTED]" in the
message body (where [EMAIL PROTECTED] is your e-mail address).
---------------End of Original Message-----------------
---------------------------------------------------------------------------
To unsubscribe from the Visual Tcl mailing list, please send a message
to [EMAIL PROTECTED] with "unsubscribe vtcl [EMAIL PROTECTED]" in the
message body (where [EMAIL PROTECTED] is your e-mail address).