Asked By John Vottero
22-Jan-10 02:48 PM

How did PowerShell's handling of stdout and stderr with native commands
change in v2.0?
We have an application that intercepts stdout and stderr by doing:
Console.SetError(new StreamWriter(ourStreamHandler));
Console.SetOut(new StreamWriter(ourStreamHandler));
then we create a Runspace and Pipeline and execute a PowerShell script.
This sent anything written to stdout or stderr to our stream handler and we
could fool with it before sending on on the the original stderr or stdout.
This worked fine with PowerShell V1.0. although, PowerShell would intercept
anything written to stderr and write a NativeCommandError to the Error
pipeline.
With PowerShell v2.0, output from PowerShell commands is interepted as
before but, when native commands write to stdout, it goes directly to the
original stdout, bypassing our interception. And, output to stderr is just
sent to stderr (and properly intercepted), a NativeCommandError is not
written to the Error pipeline.
Are these changes documented? How can I intercept the output from native
commands?