Very similar to this question - I would like to know how to display the output of an external command in real-time. I am able to display the output of a command after it's fully executed. But is it possible to display the output in real-time (as the command is executing)?
Asked
Active
Viewed 484 times
1 Answers
0
Here's an example:
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "ping.exe"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = "-n 20 google.com"
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
while (-not $p.HasExited) {
if (-not $p.StandardOutput.EndOfStream) {
# Just for fun
$lineChars = $p.StandardOutput.ReadLine().ToCharArray()
[Array]::Reverse($lineChars)
Write-Host -ForegroundColor Cyan ([System.Text.Encoding]::ASCII.GetString($lineChars))
}
}

filimonic
- 3,988
- 2
- 19
- 26
-
Thank you for your effort! This is exactly what I needed.. besides the reverse text ;) – MichaelKayal Mar 02 '21 at 09:47