Grab output from 'tail' 
Author Message
 Grab output from 'tail'

I'm looking for a way to grab the output from the UNIX command
'tail -f <filename>', displaying the output in a text frame.

Simply exec'ing the command does not do the trick; only one line is
displayed and subsequent writing to the file does not show up.  It would
seem I need to somehow actively poll for new lines written to the file,
maybe?

Has anyone done something like this before?  I would appreciate any
pointers.  Thanks,

Tom

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Tue, 02 Jul 2002 03:00:00 GMT  
 Grab output from 'tail'


Quote:
>I'm looking for a way to grab the output from the UNIX command
>'tail -f <filename>', displaying the output in a text frame.

>Simply exec'ing the command does not do the trick; only one line is
>displayed and subsequent writing to the file does not show up.  It would
>seem I need to somehow actively poll for new lines written to the file,
>maybe?

>Has anyone done something like this before?  I would appreciate any
>pointers.  Thanks,

                        .
                        .
                        .
Does <URL:http://
starbase.neosoft.com/~claird/comp.lang.tcl/tcl-examples.html#tail>
answer your questions?
--


Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html



Tue, 02 Jul 2002 03:00:00 GMT  
 Grab output from 'tail'

Quote:

> I'm looking for a way to grab the output from the UNIX command
> 'tail -f <filename>', displaying the output in a text frame.

> Simply exec'ing the command does not do the trick; only one line is
> displayed and subsequent writing to the file does not show up.  It would
> seem I need to somehow actively poll for new lines written to the file,
> maybe?

> Has anyone done something like this before?  I would appreciate any
> pointers.  Thanks,

> Tom

Of course, you don't need to use tail -f to do this, but ...

#
# tail -f a file into a text widget
#
proc tail-f {w file} {
    set fp [open "| tail -f $file" r]
    fconfigure $fp -blocking false
    fileevent $fp readable [list tail-f-progress $w $fp]

Quote:
}

proc tail-f-progress {w fp} {
    if {[eof $fp]} {
        if {[catch {close $fp} error]} {
           $w insert end $error
        }
        $w insert end "Finished\n"
    } else {
        $w insert end [read $fp]
    }

Quote:
}

-- rec --


Fri, 05 Jul 2002 03:00:00 GMT  
 Grab output from 'tail'

Quote:


> > I'm looking for a way to grab the output from the UNIX command
> > 'tail -f <filename>', displaying the output in a text frame.

> > Simply exec'ing the command does not do the trick; only one line is
> > displayed and subsequent writing to the file does not show up.  It would
> > seem I need to somehow actively poll for new lines written to the file,
> > maybe?

> > Has anyone done something like this before?  I would appreciate any
> > pointers.  Thanks,

> > Tom

> Of course, you don't need to use tail -f to do this, but ...

> #
> # tail -f a file into a text widget
> #
> proc tail-f {w file} {
>     set fp [open "| tail -f $file" r]
>     fconfigure $fp -blocking false
>     fileevent $fp readable [list tail-f-progress $w $fp]
> }
> proc tail-f-progress {w fp} {
>     if {[eof $fp]} {
>         if {[catch {close $fp} error]} {
>            $w insert end $error
>         }
>         $w insert end "Finished\n"
>     } else {
>         $w insert end [read $fp]
>     }
> }

Your implementation of tail -f is not quite right. I believe that once
you reach the end of the file and have closed it you have to keep polling
the size until it changes, reopen it, move to the end of the data you
have read and then repeat this.


Sat, 06 Jul 2002 03:00:00 GMT  
 Grab output from 'tail'

Quote:


> > Of course, you don't need to use tail -f to do this, but ...

> > #
> > # tail -f a file into a text widget
> > #
> > proc tail-f {w file} {
> >     set fp [open "| tail -f $file" r]
> >     fconfigure $fp -blocking false
> >     fileevent $fp readable [list tail-f-progress $w $fp]
> > }
> > proc tail-f-progress {w fp} {
> >     if {[eof $fp]} {
> >         if {[catch {close $fp} error]} {
> >            $w insert end $error
> >         }
> >         $w insert end "Finished\n"
> >     } else {
> >         $w insert end [read $fp]
> >     }
> > }

> Your implementation of tail -f is not quite right. I believe that once
> you reach the end of the file and have closed it you have to keep polling
> the size until it changes, reopen it, move to the end of the data you
> have read and then repeat this.

You're right, but I didn't implement tail -f, I passed an fp pointing
to [open "|tail -f $file" r] instead.

If you want to eliminate the tail -f and write a portable log
monitoring text widget, then you need to understand what Paul is
saying.

-- rec --



Sun, 07 Jul 2002 03:00:00 GMT  
 Grab output from 'tail'

Quote:

> > >     set fp [open "| tail -f $file" r]
> > >     ....
> > >     if {[eof $fp]} {
> > >         if {[catch {close $fp} error]} {
> > >            $w insert end $error
> > >         }
> > >         $w insert end "Finished\n"

> You're right, but I didn't implement tail -f, I passed an fp pointing
> to [open "|tail -f $file" r] instead.

Yes. I'm just curious to know when you expect the 'Finished' above to
pop out. An explicit kill of the tail -f ? An NFS server becoming
unavailable ? :^)

-Alex



Sun, 07 Jul 2002 03:00:00 GMT  
 Grab output from 'tail'

Quote:


> > > >     set fp [open "| tail -f $file" r]
> > > >     ....
> > > >     if {[eof $fp]} {
> > > >         if {[catch {close $fp} error]} {
> > > >            $w insert end $error
> > > >         }
> > > >         $w insert end "Finished\n"

> > You're right, but I didn't implement tail -f, I passed an fp pointing
> > to [open "|tail -f $file" r] instead.

> Yes. I'm just curious to know when you expect the 'Finished' above to
> pop out. An explicit kill of the tail -f ? An NFS server becoming
> unavailable ? :^)

Hmm, hadn't thought about it, but always happy to catch an unexpected
failure mode rather than ignore it.  In truth, I copied the code from
a pipe to read the output of cdrecord, which does terminate, and much
more successfully than it did under xcdroast's control.

-- rec --



Sun, 07 Jul 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. grabs and problems with grabs: they don't seem to work

2. GAWK with 'tail -f'

3. 'tail -f' in Tk

4. TK background 'tail -f' with expect

5. 'tail' equivalent in TCL

6. Problem with 'grab'

7. 'grab' fails for modal dialog

8. BUG?: Tk4.0b3 'grab' problems

9. 'split' creates extra output

10. Outputting 'Raw' printer data

11. Undetermined Output in 'X' state

12. Redefining 'Class'Output

 

 
Powered by phpBB® Forum Software