Title: CLI: `pwsh -Command -` and `pwsh -File -` unexpectedly exhibit pseudo-interactive behavior, lack support for argument passing · Issue #3223 · PowerShell/PowerShell · GitHub
Open Graph Title: CLI: `pwsh -Command -` and `pwsh -File -` unexpectedly exhibit pseudo-interactive behavior, lack support for argument passing · Issue #3223 · PowerShell/PowerShell
X Title: CLI: `pwsh -Command -` and `pwsh -File -` unexpectedly exhibit pseudo-interactive behavior, lack support for argument passing · Issue #3223 · PowerShell/PowerShell
Description: Related: #9497 While pwsh -Command - and pwsh -File - both accept command input from the pipeline / from stdin: they exhibit undesirable pseudo-interactive behavior: they execute each line one by one, in separate pipelines. additionally,...
Open Graph Description: Related: #9497 While pwsh -Command - and pwsh -File - both accept command input from the pipeline / from stdin: they exhibit undesirable pseudo-interactive behavior: they execute each line one by o...
X Description: Related: #9497 While pwsh -Command - and pwsh -File - both accept command input from the pipeline / from stdin: they exhibit undesirable pseudo-interactive behavior: they execute each line one by o...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/3223
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"CLI: `pwsh -Command -` and `pwsh -File -` unexpectedly exhibit pseudo-interactive behavior, lack support for argument passing","articleBody":"Related: #9497\r\n\r\nWhile `pwsh -Command -` and `pwsh -File -` both accept command input from the pipeline / from stdin:\r\n\r\n* they **exhibit undesirable pseudo-interactive behavior**:\r\n\r\n * they execute each line _one by one_, in _separate pipelines_.\r\n * additionally, `-File -` prints the prompt string and each input line before the output \r\n\r\n * they require pipelines that are spread across multiple lines for readability to be terminated with _two_ newlines (see below) - as would be necessary _interactively_, if `PSReadLine` weren't loaded.\r\n\r\n\r\n* they **do not support combining `-` input with passing _arguments_**:\r\n\r\n * While that limitation is documented for `-Command -` (`-File -` is undocumented altogether), there's no good reason for this limitation, and it limits the usefulness of the construct.\r\n\r\n * While you could (but in my mind shouldn't) argue that `-Command -` should be limited to providing a self-contained source-code snippet that doesn't expect arguments, at the least \u003cbr>`-File -` should support passing arguments by placing them after the `-` - after all, you want to be able to pass arguments to a _script_ - whether that script is specified as a a _file_ or as a script's _content_ via stdin.\r\n\r\nThus, the following command, which spreads pipeline `\"hi\" | % { \"$_ there\" }` across _two_ lines - does _not_ work:\r\n\r\n```powershell\r\n@'\r\n\"in\"\r\n\"hi\" |\r\n % { \"$_ there\" }\r\n\"out\"\r\n'@ | powershell -noprofile -command -\r\n```\r\nThe above yields _only_ `in`, because the end of the multi-line command is never detected, causing it to be _quietly ignored_.\r\n\r\nAs evidence that this happens in the real world, see [this Stack Overflow question](http://stackoverflow.com/a/42475326/45375), whose accepted answer provides more detail.\r\n\r\nInserting an empty line after the multi-line command fixes the problem:\r\n\r\n```powershell\r\n@'\r\n\"in\"\r\n\"hi\" |\r\n % { \"$_ there\" }\r\n\r\n\"out\"\r\n'@ | powershell -noprofile -command -\r\n```\r\n\r\nThe above now yields `in`, `hi there` and `out` - that is, the multi-line pipeline was correctly submitted due to the extra newline, as was the single-line statement afterwards.\r\n\r\n---\r\n\r\nSummary:\r\n\r\n* Both `File -` and `-Command -` should be fixed; and, on Unix `/dev/stdin` should be the same as passing `-`.\r\n\r\n* **If `-File -` worked properly, there'd really be no need for `-Command -`**.\r\n * _Update_: Except perhaps for emulating an interactive REPL via stdin - see https://github.com/PowerShell/PowerShell/issues/15331#issuecomment-830652350\r\n\r\n* `-File -` should optionally also accept _arguments_.\r\n\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2017-02-27T22:52:54Z","url":"https://github.com/PowerShell/PowerShell/issues/3223"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:5cf4766b-cee5-4ba7-b049-d2fc7a387240 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8672:19E595:13DDC6:1A9D0D:6AFD414F |
| html-safe-nonce | a82abf2da79e891ff10646d343c33f03f7c00506ef31e9406e061233b831823f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjcyOjE5RTU5NToxM0REQzY6MUE5RDBEOjZBRkQ0MTRGIiwidmlzaXRvcl9pZCI6IjQyNzEyMTg2NzU1NjM3MDg3NTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | edad14cc2828258b4d9074c719d55d5d86ddd307a902e73bca0e3f61a32b80a6 |
| hovercard-subject-tag | issue:210632882 |
| 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/3223/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e81c7d240d1190a4dbf4874272021290d330700ad3fd86ed54e38e5ccce734ce/PowerShell/PowerShell/issues/3223 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e81c7d240d1190a4dbf4874272021290d330700ad3fd86ed54e38e5ccce734ce/PowerShell/PowerShell/issues/3223 |
| og:image:alt | Related: #9497 While pwsh -Command - and pwsh -File - both accept command input from the pipeline / from stdin: they exhibit undesirable pseudo-interactive behavior: they execute each line one by o... |
| 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 | bdbacc25b921224ff0befcb9e629560a1255be51aec9991d6e3f95b5e9151474 |
| 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 | 556dd37bb0aceffb25724e151b5d858b3265b40b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width