Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mklement0 opened this issue Jun 18, 2020 · 1 comment · Fixed by #8053
Closed

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

mklement0 opened this issue Jun 18, 2020 · 1 comment · Fixed by #8053
Assignees
Labels
area-about Area - About_ topics area-language Area - PowerShell syntax and keywords area-native-cmds Area - native command support

Comments

@mklement0
Copy link
Contributor

mklement0 commented Jun 18, 2020

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.

@sdwheeler sdwheeler added area-about Area - About_ topics area-language Area - PowerShell syntax and keywords labels Jun 18, 2020
@sdwheeler
Copy link
Contributor

Adding links to related issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-about Area - About_ topics area-language Area - PowerShell syntax and keywords area-native-cmds Area - native command support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants