Title: Inconsistent handling of native command stderr · Issue #3996 · PowerShell/PowerShell · GitHub
Open Graph Title: Inconsistent handling of native command stderr · Issue #3996 · PowerShell/PowerShell
X Title: Inconsistent handling of native command stderr · Issue #3996 · PowerShell/PowerShell
Description: I discovered recently that the handling of stderr from native commands isn't being dealt with consistently between Windows PowerShell and Windows PowerShell ISE. Steps to reproduce $errorActionPreference="stop"; try { cmd /c nosuchexe } ...
Open Graph Description: I discovered recently that the handling of stderr from native commands isn't being dealt with consistently between Windows PowerShell and Windows PowerShell ISE. Steps to reproduce $errorActionPref...
X Description: I discovered recently that the handling of stderr from native commands isn't being dealt with consistently between Windows PowerShell and Windows PowerShell ISE. Steps to reproduce $errorAction...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/3996
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent handling of native command stderr ","articleBody":"I discovered recently that the handling of `stderr` from native commands isn't being dealt with consistently between Windows PowerShell and Windows PowerShell ISE. \r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```powershell\r\n$errorActionPreference=\"stop\"; try { cmd /c nosuchexe } catch { 'dang!' }\r\n```\r\n\r\nActual ISE behavior (expected)\r\n-----------------\r\n\r\n```none\r\ndang!\r\n```\r\nNative commands writing to `stderr` while `$errorActionPreference=\"stop\"` generate a catchable `NativeCommandError` which encapsulates the original error message in a `ErrorRecord`. It is easy to capture, analyze, and reword error messages in context.\r\n\r\nActual CLI behavior\r\n---------------\r\n\r\n```none\r\n'nosuchexe' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n```\r\n\r\nNo `NativeCommandError` is generated, no matter how `$errorActionPreference` is set. The `stderr` from the native command is piped straight through to the default process `stderr`. \r\n\r\nThis behavior is a serious loss of functionality, leading some to believe that PowerShell can't distinguish between `stderr` and `stdout`. Lots of community confusion generated because of the discrepency. See https://stackoverflow.com/questions/44488202/powershell-streaming-output/44491420#44491420, among others.\r\n\r\nAnalysis\r\n---------\r\nThe difference isn't just the ISE, I think it is related to PowerShell remote runspaces! The full info on the caught error record (in the ISE) demonstrates the underlying exception is a RemoteException like this:\r\n\r\n```powershell\r\nPS C:\\Users\\Burt_\u003e $errorActionPreference=\"stop\"; try { cmd /c nosuchexe } catch { Format-List * -force -InputObject $_ }\r\n\r\n\r\n\r\nPSMessageDetails : \r\nException : System.Management.Automation.RemoteException: 'nosuchexe' is not recognized as an internal or external \r\n command,\r\nTargetObject : 'nosuchexe' is not recognized as an internal or external command,\r\nCategoryInfo : NotSpecified: ('nosuchexe' is ...ternal command,:String) [], RemoteException\r\nFullyQualifiedErrorId : NativeCommandError\r\nErrorDetails : \r\nInvocationInfo : System.Management.Automation.InvocationInfo\r\nScriptStackTrace : at \u003cScriptBlock\u003e, \u003cNo file\u003e: line 1\r\nPipelineIterationInfo : {}\r\n```\r\n\r\n\r\n\r\nEnvironment data\r\n----------------\r\nBoth powershell.exe and powershell_ise.exe report the same version information:\r\n\r\n```powershell\r\nName Value\r\n---- -----\r\nPSVersion 5.1.15063.296\r\nPSEdition Desktop\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nBuildVersion 10.0.15063.296\r\nCLRVersion 4.0.30319.42000\r\nWSManStackVersion 3.0\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\n```\r\n","author":{"url":"https://github.com/BurtHarris","@type":"Person","name":"BurtHarris"},"datePublished":"2017-06-13T03:07:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":48},"url":"https://github.com/3996/PowerShell/issues/3996"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9d85a214-eb1f-7ee7-5d03-802c33a5ecf9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9514:1F1F98:9F7609C:D43140C:696E1FB4 |
| html-safe-nonce | 9c165ef3b21fe6d46aa106045b5886fc910200ac3e954072b26aa69f7f4d031f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTE0OjFGMUY5ODo5Rjc2MDlDOkQ0MzE0MEM6Njk2RTFGQjQiLCJ2aXNpdG9yX2lkIjoiNzcwMDMxMzIwMzA5MDAwNTk0MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cfd0d6ce7f1fb3bb3db31f3870e44bc296f45375f3cddd7603b26468c7bda0ab |
| hovercard-subject-tag | issue:235422867 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/3996/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f61da1ea8f72e4f0b99c29a55fd138a5927657fc923956ca999fe8ba1a3722de/PowerShell/PowerShell/issues/3996 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f61da1ea8f72e4f0b99c29a55fd138a5927657fc923956ca999fe8ba1a3722de/PowerShell/PowerShell/issues/3996 |
| og:image:alt | I discovered recently that the handling of stderr from native commands isn't being dealt with consistently between Windows PowerShell and Windows PowerShell ISE. Steps to reproduce $errorActionPref... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | BurtHarris |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2fbe8cba5e260284c10af515699ff9bb2d6ace05ab6c2e2e585b71d93b2812c3 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7fb3bc5c995a876085291706b75cf9b08900c338 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width