Hi all
Going round in circles here, help please.
I'm wanting to capture the out put of an exe (so I can email it after) and also display it. Am I missing something obvious?
So here's an example of how far I've got with a good old ping.
$Process = New-Object system.Diagnostics.Process
$Process.StartInfo = New-Object System.Diagnostics.ProcessStartInfo("ping","127.0.0.1")
$Process.StartInfo.RedirectStandardOutput = $true
$Process.StartInfo.RedirectStandardError = $true
$Process.StartInfo.UseShellExecute = $false
$Process.Start() | Out-Null
echo "Live output, missing last out put..."
while (!$Process.HasExited){
Write-Host $Process.StandardOutput.ReadLine()
}
$stdout = $Process.StandardOutput.ReadToEnd()
$stderr = $Process.StandardError.ReadToEnd()
echo "`nI want to show all out put in variables not just the end...`n"
Write-Host "stdout: $stdout"
Write-Host "stderr: $stderr"
This out puts this though. I want it to both out put everything as it goes along and also save everything to the variable to email later:
- the final out put is not displayed as it goes along (as it HasExited)
- ReadToEnd is just showing what was missed on point 1
Pinging 127.0.0.1 with 32 bytes of data:
I want to show all out put in variables not just the end...
stdout:
stderr:
Thank you!