簡體   English   中英

為什么“Get-Content”不能實時刷新內容?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM