你好,我想知道是否可以用茄子读取实时日志文件的最后一行,以及能够读取日志文件的第一部分的.tcl脚本im,但是它不再读取日志文件了。
发布于 2012-01-22 11:13:04
是否可以在日志文件的一行长度上设置上限?如果是这样的话,很容易得到最后一行:
# A nice fat upper bound!
set upperBoundLength 1024
# Open the log file
set f [open $logfile r]
# Go to some distance from the end; catch because don't care about errors here
catch {seek $f -$upperBoundLength end}
# Read to end, stripping trailing newline
set data [read -nonewline $f]
# Hygiene: close the logfile
close $f
# Get the last line
set lastline [lindex [split $data "\n"] end]请注意,执行seek并不是真正必要的;它只会使您不必阅读您认为不需要的绝大部分文件。
https://stackoverflow.com/questions/8958115
复制相似问题