Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Stop-Computer, Restart-Computer on Unix: inability to detect failure. #19802

Copy link
Copy link
@mklement0

Description

@mklement0
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.