There is a file being constantly rewritten at /dev/shm that I need to
read
from Tcl. Likely many times per second. I don't want it to miss
a beat.
My first idea:
while 1 {
set fp [open file r]
set content [read $fp
close $fp
}
Somehow I suspect this is a bad idea.
Probably inefficient
or maybe even dangerous (due to lock ups)?
What do you think? Is there a better way?
Under linux you won't encounter lockups, but you will encounter all >possibilibites from "not there" up to missing some data.
What do you think? Is there a better way?
The only way for us to formulate an answer to that question is for you
to tell us what you are really trying to do, instead of this Rube
Goldberg machine you've presently described.
On Wed, 7 Feb 2024 02:06:15 -0000 (UTC), Rich wrote:
Under linux you won't encounter lockups, but you will encounter all >>possibilibites from "not there" up to missing some data.
I've been watching the "Rube Goldberg machine" as you describe it :-)
and never had a case of incomplete data. But missing file quite a few
times. I had to wrap catch around it.
But the machine froze and became unresponsive on two occasions. I had
to hard reset!
What do you think? Is there a better way?
The only way for us to formulate an answer to that question is for you
to tell us what you are really trying to do, instead of this Rube
Goldberg machine you've presently described.
It's a Windows application running on Wine. It can log torrents of data
and I want to monitor that data, possibly triggering alarms. It's the
only way I can make it communicate with Tcl. At least I'm not making it
write to disk.
Would a Linux socket be more suitable? With Tcl socket capabilities?
Does it (the windows app) actually 'rewrite' the file (as in delete and >create another, or rewind to zero length and start writing again)?
set fd [open {|tail -f /tmp/logfile} RDONLY]
while {[gets $fd line] > -1} {
#do something with $line
}
On Wed, 7 Feb 2024 04:37:29 -0000 (UTC), Rich wrote:
Does it (the windows app) actually 'rewrite' the file (as in delete and >>create another, or rewind to zero length and start writing again)?
I don't know. Is there a way to find out?
I've seen my Tcl script error out (before I added 'catch')
complaining that the file was not found so I guess it is deleted and rewritten from scracth every time. But it's just my guess.
set fd [open {|tail -f /tmp/logfile} RDONLY]
while {[gets $fd line] > -1} {
#do something with $line
}
That code doesn't work. No output. I only get output with my previous approach:
That code doesn't work. No output. I only get output with my previous
approach:
That implies a delete and recreate approach (which is an odd way to do
it, but it /is/ a windows program, so....), which will be *much* harder
for you to keep up with.
On Thu, 8 Feb 2024 19:17:34 -0000 (UTC), Rich wrote:
That code doesn't work. No output. I only get output with my previous
approach:
That implies a delete and recreate approach (which is an odd way to
do it, but it /is/ a windows program, so....), which will be *much*
harder for you to keep up with.
I was going to give up because it's just an experiment, but something
odd is happening and I would like to understand it.
set feedfile "/dev/shm/myfeed.txt"
set fifofile "/dev/shm/myfeed.fifo"
exec tail -f $feedfile > $fifofile &
(build Tk GUI with text widget to display the data)
while {[gets $fd line] > -1} {
puts $line
return
(text widget insertion here, not in use yet, return aborts
it)
}
I get no output. Nothing happens.
Then I go to the directory where the fifo file is in a regular shell terminal:
$ cat myfeed.fifo
After running that command, I get all the output (ok, makes sense)
but:
1. Only in the shell terminal, not in the IDE's compiler output pane
which usually captures the output.
2. AND the Tk GUI with the text widget shows up on the screen. Empty,
but visible.
Why?
Moreover, if I remove the 'return' line, then the IDE captures the
output (because of the 'puts' line), but the Tk GUI never shows up.
Again, why?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 463 |
Nodes: | 16 (2 / 14) |
Uptime: | 157:16:32 |
Calls: | 9,384 |
Calls today: | 4 |
Files: | 13,561 |
Messages: | 6,096,000 |