$ErrorActionPreference='Continue' $py='C:\Python314\python.exe' Write-Host ("py exists: " + (Test-Path $py)) Write-Host '--- pip show glances ---' & $py -m pip show glances 2>&1 | Select-String -Pattern 'Name:|Version:' | ForEach-Object { Write-Host $_ } Write-Host '--- 前台跑 glances 8秒(输出重定向到文件) ---' $log="$env:TEMP\gl" Start-Process $py -ArgumentList '-m','glances','-w','--disable-webui','-t','5' -RedirectStandardError "$log.err" -RedirectStandardOutput "$log.out" -WindowStyle Hidden Start-Sleep 8 Write-Host ('listen 61208: ' + (Test-NetConnection 127.0.0.1 -Port 61208 -WarningAction SilentlyContinue).TcpTestSucceeded) Write-Host '--- glances stderr ---' Get-Content "$log.err" -ErrorAction SilentlyContinue | Select-Object -Last 12 | ForEach-Object { Write-Host $_ }