Jump to content


Photo

Equivalent of tail -f?


  • Please log in to reply
7 replies to this topic

#1 lzo

lzo
  • Members
  • 3 posts

Posted 09 June 2012 - 01:43 PM

I've searched and found some tail functions but they seem to be from like six or seven years ago, I don't know if anything has changed which is why I`m asking


I need to kill a process in response to something -- as soon as "The batch process has completed." appears in c:\grep\parser.log, kill the process

do I use
IfWinExist, Analytical6 - Done ; assuming that is the full window title 
    WinKill
and how to implement the tail -f equivalent? Can someone point me in a direction?


Thanks, very much appreciate

#2 engunneer

engunneer
  • Fellows
  • 9162 posts

Posted 09 June 2012 - 03:28 PM

I'd start with hugoV's TF library. the TF_Tail function should do what you want and is current

#3 lzo

lzo
  • Members
  • 3 posts

Posted 10 June 2012 - 05:10 PM

I'd start with hugoV's TF library. the TF_Tail function should do what you want and is current

Found it, but how do I make it monitor the file and automatically check the last line when the file changes?

#4 engunneer

engunneer
  • Fellows
  • 9162 posts

Posted 11 June 2012 - 12:59 AM

you have to write your own loop for that. A better option might be SetTimer, which can run a label periodically. Get the tail of the file every 100ms, and see if it contains what you look for.

#5 guest3456

guest3456
  • Members
  • 1334 posts

Posted 11 June 2012 - 02:24 AM

i dont know about hugovs library but i reposted a tail function i found on the forums here:

<!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?p=400494#p400494">viewtopic.php?p=400494#p400494</a><!-- l -->

edit/
just looked at hugov's library and it seems to wrap the built in ahk commands which keeps the whole file in memory as lazlo notes:

The point of this 3.5 years old thread was to get the last line of a text file, without keeping the whole file in memory. Even if the file fits to the RAM, the memory usage gets large, which may cause other applications to slow down.

During the last three years we learned how to seek and read only portions of the file, so there are much faster methods for huge files.



#6 Guests

  • Guests

Posted 11 June 2012 - 07:09 AM

If you want the "latest" use AutoHotkey_L and the file object nicely wrapped by just me here <!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?f=13&t=85135&hilit=tail">viewtopic.php?f=13&t=85135&hilit=tail</a><!-- l -->

(tf_tail has a number of other options for flexibility and is not intended to be fastest or continuously monitor files as such. It does not hold the file in memory but does read it in its entirety each time you call it which could be problematic for large files or rapidly growing files)

#7 guest3456

guest3456
  • Members
  • 1334 posts

Posted 11 June 2012 - 02:15 PM

(tf_tail has a number of other options for flexibility and is not intended to be fastest or continuously monitor files as such. It does not hold the file in memory but does read it in its entirety each time you call it which could be problematic for large files or rapidly growing files)


yeah i'm pretty sure thats what lazlo meant. when you have to read the entire file, the variable takes up memory

#8 lzo

lzo
  • Members
  • 3 posts

Posted 12 June 2012 - 01:41 AM

I want to constantly read new line on file, then check if a string (not regex, hopefully.. i dont know how to deal with regex) exist in it, and if so, run a command (like "batch is complete" in full line of "8:41:55p ! Batch is complete in 300s.")

I don't do programming before and kind of find this hard to follow, sorry..