首页 > 解决方案 > 如何在 Julia 中连续读取不断增长的日志文件的新附加行?

问题描述

有shell命令:

tail -n0 -f /path/to/growing/log

连续显示文件新添加的行。

请指导我实现 Julia 的目标!

标签: file-iojulia

解决方案


只是反复读取文件:

file = open("/path/to/growing/log")
seekend(file) # ignore contents that are already there to match the `-n0` option

while true
    sleep(0.2)
    data = read(file, String)
    !isempty(data) && print(data)
end

推荐阅读