Skip to content

An errant space is inserted in command line when parameter starting with dash and it has a dot. -DFOO=foo.c  #14364

Closed

Description

Steps to reproduce

When you are calling a program from the command line, if the command line has a parameter that starts with a dash, and it contains a dot, powershell (pwsh and windows powershell) inserts a space and breaks up the parameter into two parameters

this can be demonstrated with cmd with echo

cmd /c echo -DFOO=path/to/foo.c 

Expected behavior

-DFOO=path/to/foo.c

Actual behavior

-DFOO=path/to/foo .c

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.0
PSEdition                      Core
GitCommitId                    7.1.0
OS                             Microsoft Windows 10.0.21276
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Dec 9, 2020
  2. jborean93 commented on Dec 9, 2020

    @jborean93
    Collaborator

    A workaround is to use --% -DFOO=path/to/foo.c or just quote the argument.

  3. mklement0 commented on Dec 9, 2020

    @mklement0
    Contributor

    An unfortunate bug, but it has been known for a while: #6291

    There are related bugs as well: https://github.com/PowerShell/PowerShell/issues?q=is%3Aissue+is%3Aopen+parameter+parsing+in%3Atitle

    GitHub
    PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.
  4. mklement0 commented on Dec 9, 2020

    @mklement0
    Contributor

    I just realized that `-escaping the leading - is another workaround that also helps with some of the other linked issues:

    cmd /c echo `-DFOO=path/to/foo.c
    

    (Re quoting: '...' or "..."-quoting any part of the argument helps too, such as -DFOO='path/to/foo.c', but it's important to note in general that selective quoting is not passed through as such to the target executable - on-demand re-quoting is performed).

  5. ghost closed this as completedon Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-DuplicateThe issue is a duplicate.WG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions