Skip to content

Document the specific constraints of the stop-parsing symbol (--%) #6149

@mklement0

Description

@mklement0

It is worth clarifying the following limitations, notably the one with respect to what causes --% to stop parsing (see PowerShell/PowerShell#12975):

  • --% supports only one command, which an unquoted |, || or && on the same line, if present, implicitly ends; this allows you to pipe / chain such a command to / with other commands.

    • However, using ; in order to unconditionally place another command on the same line is not supported; the ; is passed through verbatim.

    • --% reads (at most) to the end of the line so spreading a command across multiple lines with line-continuation chars. is NOT supported

  • Other than %...% environment-variable references, you cannot embed any other dynamic elements in the command; that is, you cannot embed regular PowerShell variable references or expressions.

    • Escaping % characters as %% (the way you can do inside batch files) is not supported; %<name>% tokens are invariably expanded, if <name> refers to a defined environment variable (if not, the token is passed through as-is).
  • You cannot use stream redirections (e.g., >file.txt), because they are passed verbatim, as arguments to the target command.

    • For stdout output you can work around that by appending | Set-Content file.txt instead, but there is no direct PowerShell workaround for stderr output.

    • However, if you invoke your command via cmd, you can let cmd handle the (stderr) redirection (e.g., cmd --% /c nosuch 2>file.txt)

#4963 discusses why, specifically, --% is virtually useless on Unix-like platforms (the about_Parsing topic now mentions that, but just in the abstract ("The stop-parsing symbol only intended for use on Windows platforms.")).


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Labels

area-aboutArea - About_ topicsarea-languageArea - PowerShell syntax and keywordsarea-native-cmdsArea - native command support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions