Title: Stop-Computer, Restart-Computer on Unix: inability to detect failure. · Issue #19802 · PowerShell/PowerShell · GitHub
Open Graph Title: Stop-Computer, Restart-Computer on Unix: inability to detect failure. · Issue #19802 · PowerShell/PowerShell
X Title: Stop-Computer, Restart-Computer on Unix: inability to detect failure. · Issue #19802 · PowerShell/PowerShell
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 reprodu...
Open Graph 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 PowerSh...
X 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 PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/19802
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Stop-Computer, Restart-Computer on Unix: inability to detect failure.","articleBody":"### Prerequisites\r\n\r\n- [X] Write a descriptive title.\r\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\r\n- [X] Search the existing issues.\r\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://docs.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\r\n\r\n### Steps to reproduce\r\n\r\nOn Unix, these commands defer to the native `/sbin/shutdown` utility.\r\n\r\nHowever, the way in which this is currently implemented makes it impossible to detect failure _programmatically_:\r\n\r\nE.g., on macOS, _without_ using `sudo`, run the following:\r\n\r\n```\r\n# Run *without* sudo, so as to provoke failure of /sbin/shutdown\r\nStop-Computer -ErrorVariable e 2\u003e$null || Write-Error \"Shutdown initiation failed.\"\r\n```\r\n\r\nNote that running `/sbin/shutdown` directly in the scenario above:\r\n\r\n* prints `shutdown: NOT super-user` to stderr\r\n* reports `1` as its exit code\r\n\r\n\r\n### Expected behavior\r\n\r\nNo visible output (due to `2\u003e$null`), the error message stored in `$e`, and `$?` indicating `$false` so that the `||` clause is triggered.\r\n\r\n\r\n### Actual behavior\r\n\r\n`shutdown`'s stderr prints directly to the terminal, bypassing all PowerShell streams.\r\n`$?` reflects `$true` afterwards.\r\n\r\nIn other words: there is no way to detect failure.\r\n\r\n\r\n### Error details\r\n\r\n_No response_\r\n\r\n### Environment data\r\n\r\n```powershell\r\nPowerShell 7.4.0-preview.3 on macOS and Linux\r\n```\r\n\r\n\r\n### Visuals\r\n\r\n_No response_","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2023-06-14T15:26:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/19802/PowerShell/issues/19802"}
| 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:664ca7df-9741-9d22-4c39-a4683ccee5af |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B93C:2CE7AA:1723322:1EA3C57:6A543BE1 |
| html-safe-nonce | 6cf1c3e4f648055a98f6a3bf5661bcb86fba064e1007eea40c45fc4d4f8c9104 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTNDOjJDRTdBQToxNzIzMzIyOjFFQTNDNTc6NkE1NDNCRTEiLCJ2aXNpdG9yX2lkIjoiNTA1ODc2ODU0MDY0OTQwNTQwOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cfdb140dee13e81cefe371145f35ca0c2f0aeffb2883b60a5b72beb233648a4d |
| hovercard-subject-tag | issue:1757162680 |
| 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/19802/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e2b64f87618d20e760ad73cadf5fc5a43a3aa03aed34d7aa8924828cb051d65c/PowerShell/PowerShell/issues/19802 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e2b64f87618d20e760ad73cadf5fc5a43a3aa03aed34d7aa8924828cb051d65c/PowerShell/PowerShell/issues/19802 |
| og:image:alt | 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 PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width