In a powershell script, I call a program and want to redirect stdout
and stderr
to different files, while still showing the output of both in the console. So basically, I want
stdout -> stdout
stdout -> out.log
stderr -> stderr
stderr -> err.log
So far, I came up with this code, but unfortunately it only fulfils requirements 1, 2 and 4. Stderr is not printed on the screen.
& program 2>"err.log" | Tee-Object -FilePath "out.log" -Append | Write-Host
How can I print stderr
to the console also? Since writing to stderr
produces red typeface, I don't want to redirect stderr
to stdout
, since then I would lose the visual impression of the error.