본문 바로가기

카테고리 없음

Windows에서 flickering없이 watch command 구현

nvidia-smi를 실행하는 예제:

Clear-Host 

while ($true) {
    # Move cursor to top-left (0,0) to overwrite previous output
    $Host.UI.RawUI.CursorPosition = @{X=0; Y=0}
    
    nvidia-smi
    
    Start-Sleep -Seconds 0.1
}

 

아래는 함수로 래핑

function watch-smi {
    param (
        [double]$Seconds = 0.1
    )

    # 1. Clear the screen initially to remove old prompt text
    Clear-Host

    # 2. Infinite loop
    while ($true) {
        # Reset cursor to top-left to avoid flickering
        $Host.UI.RawUI.CursorPosition = @{X=0; Y=0}
        
        nvidia-smi
        
        Start-Sleep -Seconds $Seconds
    }
}