Spaces in commandline path #21211

Closed
opened 2026-01-31 07:36:39 +00:00 by claunia · 5 comments
Owner

Originally created by @taschemann on GitHub (Feb 6, 2024).

Windows Terminal version

1.18.231114001

Windows build number

10

Other Software

No response

Steps to reproduce

I'm trying to load a custom PowerShell profile that is stored in %OneDrive%, but the path to OneDrive contains multiple spaces in it and I can't figure out how to escape the spaces, even when I spell the path out and explicitly escape them. This is my employer's setup, so the path can't be changed and I can't put the PowerShell profile in a different location. Is it possible to load the profile with Windows Terminal? Can I escape the spaces somehow?

Expected Behavior

I want to use powershell.exe -File %OneDrive%/path/to/profile.ps1 and have the profile load, whether there are spaces in the path or not.

Actual Behavior

PowerShell doesn't start because the path can't be traversed properly.

Originally created by @taschemann on GitHub (Feb 6, 2024). ### Windows Terminal version 1.18.231114001 ### Windows build number 10 ### Other Software _No response_ ### Steps to reproduce I'm trying to load a custom PowerShell profile that is stored in %OneDrive%, but the path to OneDrive contains multiple spaces in it and I can't figure out how to escape the spaces, even when I spell the path out and explicitly escape them. This is my employer's setup, so the path can't be changed and I can't put the PowerShell profile in a different location. Is it possible to load the profile with Windows Terminal? Can I escape the spaces somehow? ### Expected Behavior I want to use `powershell.exe -File %OneDrive%/path/to/profile.ps1` and have the profile load, whether there are spaces in the path or not. ### Actual Behavior PowerShell doesn't start because the path can't be traversed properly.
claunia added the Needs-TriageIssue-BugNeeds-Author-FeedbackNo-Recent-Activity labels 2026-01-31 07:36:39 +00:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 6, 2024):

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@github-actions[bot] commented on GitHub (Feb 6, 2024): Hi I'm an AI powered bot that finds similar issues based off the issue title. Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you! ### Closed similar issues: - [Path environment variable with spaces cannot be passed into cmd/powershell terminal (#1847)](https://github.com/microsoft/terminal/issues/1847), similarity score: 0.77 > Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Author
Owner

@zadjii-msft commented on GitHub (Feb 6, 2024):

What's the commandline set to in your settings.json file/?

I'd expect something like

"commandline": "powershell.exe -File \"%OneDrive%/path/to/profile.ps1\""

to work well enough. The inner quotes should get stripped out as CreateProcess passes that arg to powershell.exe, so it should just receive that as a single arg

@zadjii-msft commented on GitHub (Feb 6, 2024): What's the `commandline` set to in your [settings.json file](https://github.com/microsoft/terminal/wiki/Frequently-Asked-Questions-(FAQ)#where-can-i-find-the-settings-file)/? I'd expect something like ```json "commandline": "powershell.exe -File \"%OneDrive%/path/to/profile.ps1\"" ``` to work well enough. The inner quotes _should_ get stripped out as `CreateProcess` passes that arg to `powershell.exe`, so it should just receive that as a single arg
Author
Owner

@taschemann commented on GitHub (Feb 6, 2024):

Thank you for the reply! When I format the string as you instructed, I get The term 'C:\Users\name\OneDrive' is not recognized as... and PowerShell exits with 0x00000001. The portion of the path after the space gets cuts off. That's when I tried defining the full path without using variables but that didn't work either.

C:\\Users\\name\\\"OneDrive with spaces\"\\path\\to\\profile.ps1
C:\\Users\\name\\\OneDrive\u0020with\u0020spaces\\path\\to\\profile.ps1

@taschemann commented on GitHub (Feb 6, 2024): Thank you for the reply! When I format the string as you instructed, I get `The term 'C:\Users\name\OneDrive' is not recognized as...` and PowerShell exits with 0x00000001. The portion of the path after the space gets cuts off. That's when I tried defining the full path without using variables but that didn't work either. `C:\\Users\\name\\\"OneDrive with spaces\"\\path\\to\\profile.ps1` `C:\\Users\\name\\\OneDrive\u0020with\u0020spaces\\path\\to\\profile.ps1`
Author
Owner

@zadjii-msft commented on GitHub (Feb 6, 2024):

Huh. Weird. Admittedly, I don't have the same `%onedrive% env var set up, but I tried with

            {
                "name": "gh-16674",
                "commandline": "PowerShell.exe -File \"%userprofile%\\OneDrive - Microsoft\\Documents\\PowerShell\\gh-16674.ps1\""
            },

(where %userprofile% is set to c:\users\migrie)

and that works just fine. Maybe the %onedrive% variable has another set of quotes already inside it? That would be... kinda weird, but might explain this

@zadjii-msft commented on GitHub (Feb 6, 2024): Huh. Weird. Admittedly, I don't have the same `%onedrive% env var set up, but I tried with ```json { "name": "gh-16674", "commandline": "PowerShell.exe -File \"%userprofile%\\OneDrive - Microsoft\\Documents\\PowerShell\\gh-16674.ps1\"" }, ``` (where `%userprofile%` is set to `c:\users\migrie`) and that works just fine. Maybe the %onedrive% variable has another set of quotes already inside it? That would be... kinda weird, but might explain this
Author
Owner

@microsoft-github-policy-service[bot] commented on GitHub (Feb 11, 2024):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@microsoft-github-policy-service[bot] commented on GitHub (Feb 11, 2024): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**. <!-- Policy app identification https://img.shields.io/static/v1?label=PullRequestIssueManagement. -->
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#21211