A
A
Alexey2014-10-13 20:24:44
linux
Alexey, 2014-10-13 20:24:44

Is there an analogue of unix tail for windows (with sources)?

Good day!
In tail , the -f switch provides the ability to output data coming into the file as it grows. I would like to know how to implement it under windows.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lolshto, 2014-10-13
@Lol4t0

In general, coreutils are compiled for windows, so you can look at the original code .
But in general, there is nothing complicated in implementing such behavior. In the simplest case, you can do this:

#include <fstream>
#include <iostream>
#include <string>

int main()
{
    std::ifstream s("test");
    while (true) {
        if (!s.eof()) {
            std::string line;
            if (std::getline(s, line)) {
                std::cout << line << '\n';
            }
        }
        else {
            s.clear();
        }
    }
}

In reality, it would be nice to keep an eye on the file, rather than trying to read from it all the time
--
If you just need tail under windows, then use tail from the compiled coreutils

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question