You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
$ErrorActionPreference doesn't affect stderr output for native commands #6466
The PR PowerShell/PowerShell#13361 made a breaking change that $ErrorActionPreference doesn't affect stderr output for native commands.
Also the error records generated from the stderr output of native commands are not put in $Error and variable specified by -ErrorVariable.
I think what needs to be said should be a bit more detailed on the user impact even though Dongbo Wang (@daxian-dbw)'s content is technically correct:
Previously, when stderr was redirected (like ls foo 2>$null), if the native command wrote to stderr, then it resulted in an ErrorRecord written to $Error. This also meant that $ErrorActionPreference was affected by this ErrorRecord. With PowerShell7.1, we recognized that many native commands write to stderr not as error messages, but an alternate stream for additional information that doesn't make sense to write to stdout. This includes content such as verbose or progress output.
I'm also working on a PR that is related to this and should be documented at the same time. Because stderr is no longer a means to indicate a native command has error'd. This means that $? which tells you if the last command succeeded or failed, should indicate succeeded if the native command exit code is 0 despite any content written to stderr.
This information should eventually also be incorporated into the proposed conceptual help topic about calling external (native) executables - see #5152.
Can we consider implementing this as a straight bug fix?
The current behavior is useless and counterintuitive:
If I execute ls nosuch 2>$null or ls nosuch 2>err.txt, the intent is clearly to silence / capture all stderr output - and not to abort the command just because $ErrorActionPreference happens to be set to 'Stop' (which without the 2> redirection would have no impact on the command).
Activity
SteveL-MSFT commentedon Aug 10, 2020
I think what needs to be said should be a bit more detailed on the user impact even though Dongbo Wang (@daxian-dbw)'s content is technically correct:
ls foo 2>$null), if the native command wrote to stderr, then it resulted in an ErrorRecord written to $Error. This also meant that$ErrorActionPreferencewas affected by this ErrorRecord. With PowerShell7.1, we recognized that many native commands write to stderr not as error messages, but an alternate stream for additional information that doesn't make sense to write to stdout. This includes content such as verbose or progress output.$?which tells you if the last command succeeded or failed, should indicate succeeded if the native command exit code is 0 despite any content written to stderr.mklement0 commentedon Aug 11, 2020
This information should eventually also be incorporated into the proposed conceptual help topic about calling external (native) executables - see #5152.
chasewilson commentedon Aug 12, 2020
Just for Record and clarity, as of right now, this is an experimental feature and should be documented as such correct Dongbo Wang (@daxian-dbw) , Steve Lee (@SteveL-MSFT) ?
mklement0 commentedon Aug 12, 2020
Speaking of, Steve Lee (@SteveL-MSFT):
Can we consider implementing this as a straight bug fix?
The current behavior is useless and counterintuitive:
If I execute
ls nosuch 2>$nullorls nosuch 2>err.txt, the intent is clearly to silence / capture all stderr output - and not to abort the command just because$ErrorActionPreferencehappens to be set to'Stop'(which without the2>redirection would have no impact on the command).Fixes #6466 - New ErrorActionPreference Experimental Feature (#6505)