こんにちは私は、eggdropと.tclスクリプトを使用してリアルタイムログファイルの最後の行を読み取ることができるかどうか疑問に思っていましたが、ログファイルの最初の部分を読み取ることはできませんが、それ以上は読み取れません
2110 次
1 に答える
2
ログファイルの行の長さに上限を置くことは可能ですか? その場合、最後の行を取得するのは非常に簡単です。
# 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
おそらく不要なファイルの大部分を読み取る必要がなくなるだけです。
于 2012-01-22T11:13:04.527 に答える