Repository navigation
Passing a path ending with a backslash to a native command appends trailing quote #28130
Copy link
Copy link
Open
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
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.1Visuals
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.
Activity
mklement0 commentedon Sep 30, 2026
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 inC:\Windows\System32\WindowsPowerShellwhose 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.