-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Closed
Labels
Documentation Needed in this repoDocumentation is needed in this repoDocumentation is needed in this repoIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Description
Related: #4613
The .HadErrors
property of [System.Management.Automation.PowerShell]
currently invariably - and unexpectedly - reflects $True
in the following situations:
-
an external utility reports a nonzero exit code - even overriding
$LASTEXITCODE
later doesn't help that. -
something writes to PowerShell's error stream, notably including stderr output from an external utility.
Generally, having a separate property that reflects $LASTEXITCODE
would be helpful - see #5426
Examples
# Yields $True - triggered by nonzero exit code
$ps = [PowerShell]::Create().AddScript({ whoami -nosuch }); $ps.Invoke(); $ps.HadErrors
# Unexpectedly also yields $True - despite attempt to set the exit code to 0.
$ps = [PowerShell]::Create().AddScript({ whoami -nosuch; $LASTEXITCODE = 0 }); $ps.Invoke(); $ps.HadErrors
# Unexpectedly also yields $True - triggered by native stderr output.
$ps = [PowerShell]::Create().AddScript({ bash -c 'echo err >&2' }); $ps.Invoke(); $ps.HadErrors
Environment data
PowerShell Core v6.0.0-beta.9 on macOS 10.13
PowerShell Core v6.0.0-beta.9 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0-beta.9 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.674 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Metadata
Metadata
Assignees
Labels
Documentation Needed in this repoDocumentation is needed in this repoDocumentation is needed in this repoIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime