I encountered this behavior in Powershell and I was wondering why is this happening:
Running this script:
$ErrorActionPreference= "Stop"
cmd /c "echo error 1>&2" 2>log.txt
Produces the following output:
PS D:\playground\Powershell> .\Redirecting-Stderr.ps1
cmd : error
At D:\playground\Powershell\Redirecting-Stderr.ps1:3 char:1
+ cmd /c "echo error 1>&2" 2>log.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (error :String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Actually, it doesn't matter what I'm redirecting to, it could be also $null, &1, etc.
Seems that the mere redirecting of stderr in powershell causes some exception to be raised. Why is that?
Powershell version: 5.1.17763.1490