-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issue
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
On Unix, these commands defer to the native /sbin/shutdown utility.
However, the way in which this is currently implemented makes it impossible to detect failure programmatically:
E.g., on macOS, without using sudo, run the following:
# Run *without* sudo, so as to provoke failure of /sbin/shutdown
Stop-Computer -ErrorVariable e 2>$null || Write-Error "Shutdown initiation failed."
Note that running /sbin/shutdown directly in the scenario above:
- prints
shutdown: NOT super-userto stderr - reports
1as its exit code
Expected behavior
No visible output (due to 2>$null), the error message stored in $e, and $? indicating $false so that the || clause is triggered.
Actual behavior
shutdown's stderr prints directly to the terminal, bypassing all PowerShell streams.
$? reflects $true afterwards.
In other words: there is no way to detect failure.
Error details
No response
Environment data
PowerShell 7.4.0-preview.3 on macOS and LinuxVisuals
No response
Metadata
Metadata
Assignees
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issue