Some program constantly adds a certain number of lines to the Nth number of files. I need to check whether the file has changed in the loop, and if something has been added to it, then read this information. All files have the usual txt extension. Is there a ready-made solution in the qt framework? so to say "out of the box."
- exactly what you want - out of the box does not exist - Sublihim
- fiveThere is such a thing QFileSystemWatcher, it will allow you to track the fact of a file change. You can check the checksum of a file once in a while, if it has changed, then something is written. These are two options offhand, depending on the initial requirements (on the required responsiveness of the reader program to change the file) - Bearded Beaver
1 answer
There is such a tail bike from GNU core utilities .
# dpkg -S `which tail` coreutils: /usr/bin/tail You can run tail -F /var/log/*.log , -F - the flag tells the utility to keep track of changes.
Thus your problem is solved.
Raw tail on c : http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c
Nightmarish of course, but only 2400 lines.
2234 int main (int argc, char **argv) {
there fill headers (headers) then on the line
2328 for (i = 0; i < n_files; i++) ok &= tail_file (&F[i], n_units);
the matryoshka is launched from tails to files that are already in the headers.
1885 static bool tail_file (struct File_spec *f, uintmax_t n_units) {
inside it is simply called tail ()
1871 static bool tail (const char *filename, int fd, uintmax_t n_units, uintmax_t *read_pos)
tail_lines() is called there
1809 static bool tail_lines (const char *pretty_filename, int fd, uintmax_t n_lines, uintmax_t *read_pos)
And then there are just lseek-s pieces pulled out ... In general, it can help.
As a last resort, you can run tail -F {Ваш,Список,Файлов} as a subprocess, and catch the pipe from it ...