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

CLI: pwsh -Command - and pwsh -File - unexpectedly exhibit pseudo-interactive behavior, lack support for argument passing #3223

Copy link
Copy link
@mklement0

Description

@mklement0
Issue body actions

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, -File - prints the prompt string and each input line before the output
    • 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.

  • they do not support combining - input with passing arguments:

    • 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.

    • 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
      -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.

Thus, the following command, which spreads pipeline "hi" | % { "$_ there" } across two lines - does not work:

@'
"in"
"hi" |
  % { "$_ there" }
"out"
'@ | powershell -noprofile -command -

The above yields only in, because the end of the multi-line command is never detected, causing it to be quietly ignored.

As evidence that this happens in the real world, see this Stack Overflow question, whose accepted answer provides more detail.

Inserting an empty line after the multi-line command fixes the problem:

@'
"in"
"hi" |
  % { "$_ there" }

"out"
'@ | powershell -noprofile -command -

The 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.


Summary:

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Interactive-Consolethe console experiencethe console experience

    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.