Prerequisites
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-user to stderr
- reports
1 as 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 Linux
Visuals
No response
Prerequisites
Steps to reproduce
On Unix, these commands defer to the native
/sbin/shutdownutility.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:Note that running
/sbin/shutdowndirectly in the scenario above:shutdown: NOT super-userto stderr1as its exit codeExpected behavior
No visible output (due to
2>$null), the error message stored in$e, and$?indicating$falseso that the||clause is triggered.Actual behavior
shutdown's stderr prints directly to the terminal, bypassing all PowerShell streams.$?reflects$trueafterwards.In other words: there is no way to detect failure.
Error details
No response
Environment data
Visuals
No response