Visitar URL original
Passing a path ending with a backslash to a native command appends trailing quote · Issue #28130 · PowerShell/PowerShell · GitHub
Skip to content

Passing a path ending with a backslash to a native command appends trailing quote #28130

Description

@fynkxo

Prerequisites

Steps to reproduce

Description

When a Windows native C++ program is invoked from PowerShell with a single-quoted path ending in a backslash, an unexpected double quote (") is appended to the argument.

For example:

.\test.exe 'C:\Test Draw\3D\3D\50obj\'

The C++ program prints the following:

argv[0]:D:\**\test.exe
argv[1]:C:\Test Draw\3D\3D\50obj"

The expected value of argv[1] is:

C:\Test Draw\3D\3D\50obj\

but the actual value contains an unexpected trailing double quote:

C:\Test Draw\3D\3D\50obj"

This causes filesystem operations using the argument to fail. For example:

std::filesystem::exists(std::filesystem::path{argv[1]})

returns false because the resulting path is invalid.

Expected behavior

The trailing backslash should be preserved as part of the argument, without adding an extra double quote:

argv[1]:C:\Test Draw\3D\3D\50obj\

Expected behavior

C:\Test Draw\3D\3D\50obj\

Actual behavior

C:\Test Draw\3D\3D\50obj"

Error details

Environment data

Name                           Value                                                                                                                                            
----                           -----                                                                                                                                            
PSVersion                      5.1.19041.6456                                                                                                                                   
PSEdition                      Desktop                                                                                                                                          
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                          
BuildVersion                   10.0.19041.6456                                                                                                                                  
CLRVersion                     4.0.30319.42000                                                                                                                                  
WSManStackVersion              3.0                                                                                                                                              
PSRemotingProtocolVersion      2.3                                                                                                                                              
SerializationVersion           1.1.0.1

Visuals

No response

Activity

  1. added
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Sep 30, 2026
  2. mklement0 commented on Sep 30, 2026

    @mklement0
    Contributor

    Please note that this repo is exclusively for Powershell (Core) 7 (pwsh.exe / pwsh), and not also for Windows PowerShell (powershell.exe, the legacy, ships-with-Windows, Windows-only closed-source edition of PowerShell located in C:\Windows\System32\WindowsPowerShell whose latest and final version is 5.1)

    What you're seeing ia a well-known bug in Window PowerShell that has since been fixed in PowerShell (Core) 7.3+

    Given that Windows PowerShell will see security-critical fixes only, it is highly unlikely that the problem will be fixed there.
    One workaround: double the \ at the end of the string: .\test.exe 'C:\Test Draw\3D\3D\50obj\\'

    For background information, see this Stack Overflow answer.

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

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions