[英]Why "Get-Content" is not refreshing contents live?
我有一個日志文件並使用命令Get-Content myLog.log –Wait
來顯示這個文件的內容,就像使用 linux 等效的tail
。
我注意到內容沒有像我從tail
知道的那樣實時更新。 內容僅在特定時間間隔后刷新。 如何更改間隔,我想我必須為Wait
傳遞一個參數,以便它知道要等待多長時間?
Get-Content cmdlet 不公開用於設置刷新間隔的屬性或函數。 你可能必須自己做:
$linesPrinted = 0;
while ($true)
{
$content = Get-Content myLog.log
$currentLineCount = $content | Measure-Object -Line | select -expand Lines
if ($currentLineCount -gt $linesPrinted)
{
$content[$linesPrinted .. $currentLineCount]
$linesPrinted = $currentLineCount
}
Sleep -Milliseconds 100
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.