Skip to content

command:pickArgs behaves differently as value vs array #635

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

Open
karthiknadig opened this issue Feb 26, 2025 · 6 comments
Open

command:pickArgs behaves differently as value vs array #635

karthiknadig opened this issue Feb 26, 2025 · 6 comments
Assignees
Labels
triage-needed Needs assignment to the proper sub-team
Milestone

Comments

@karthiknadig
Copy link
Member

In particular,

"args": "${command:pickArgs}",

has a different behaviour with respect to

"args": ["${command:pickArgs}"],

In particular, in one case the full program command path (e.g. C:\Program Files\Python312) does not get escaped, in the other case it gets proper escaping, causing Visual Studio Code to fail because of the spaces.

I don't know if args parameter cannot be specified in both these ways but I think that program path must be quoted the same way in both cases to avoid these kind of issues.

Edit: output is similar to what was already attached in the opening post.

Thanks!

Originally posted by @fgiancane8 in #351

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 26, 2025
@eleanorjboyd
Copy link
Member

I think I need to look at this problem more comprehensively- I saw another complaint about the behavior as it stands and I am not sure if the change made in a recent PR helped or hurt the problem

@eleanorjboyd eleanorjboyd added this to the March 2025 milestone Feb 26, 2025
@fgiancane8
Copy link

Thanks @eleanorjboyd for your message. I opened a similar issue a year ago and it was marked as completed and duplicate of #233 but sounds like it's still there. Maybe is the same issue you're referring to?

@eleanorjboyd
Copy link
Member

Hi @fgiancane8, yes that thread is connected. The issue I fixed recently was this. Have you tried no config debugging for your use case? Here is the wiki page about it. If I understand correctly, you are attempting to provide args like path/with spaces/python arg where you want to provide a path with a space (that isn't split) than an arg that is split for the path by the space. I think no config debugging provides a better option for combining split and not split on spaces but would appreciate clarity if this is not your use case.

@fgiancane8
Copy link

Hello @eleanorjboyd thanks for coming back at me! So this is the issue i came across.
Using

    "configurations": [
        {
            "name": "Debug: Current File (Arguments)",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": "${command:pickArgs}",
            "justMyCode": true
        }

That is, args is not an array type, if starting debugging from the VS Code GUI, this is the error I get:

PS C:\Users\fgiancan\source\repos\test>  c:; cd 'c:\Users\fgiancan\source\repos\test'; c:\Program Files\Python312\python.exe c:\Users\fgiancan\.vscode\extensions\ms-python.debugpy-2025.0.1-win32-x64\bundled\libs\debugpy\launcher 55187 -- C:\Users\fgiancan\source\repos\test\test.py  
c:\Program: The term 'c:\Program' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

As you can see, my interpreter path is not quoted, since this is installed from python.org and not as a Windows App, it will be installed in C:\Program Files. That single space is messing with powershell.

On the contrary, if you use this configuration

    {
            "name": "Debug: Current File (Arguments)",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": [
                "${command:pickArgs}"
            ],
            "justMyCode": true
        },

which has args as an array type, this is what we get

PS C:\Users\fgiancan\source\repos\test>  c:; cd 'c:\Users\fgiancan\source\repos\test'; & 'c:\Program Files\Python312\python.exe' 'c:\Users\fgiancan\.vscode\extensions\ms-python.debugpy-2025.0.1-win32-x64\bundled\libs\debugpy\launcher' '55261' '--' 'C:\Users\fgiancan\source\repos\test\test.py' '' 

As you can see, this time, the interpreter path is (correctly) quoted so that the single space in Program Files does not interfere.
Hope this clarified the issue here. Interpreter path is being quoted/not quoted just on args type (array vs scalar) which seems wrong to me, or, at least, the args variable should be doing nothing regarding the interpreter.

I saw your fix mentioned in the previous issue but i'd say the interpreter choice and quoting should be more robust irregardless of whether launch.json is the new format or the old one.

@MichaelCourter64
Copy link

Hi, I also had a problem with my python exe path having a space character and not being enclosed in quotes when running a script on my PC.

My project didn't have a launch file a couple weeks ago and was running the script fine. I would just have to occasionally specify how I wanted to run it when the command palette appeared: debug configuration, Python with arguments.

But now, without any apparent change (auto update is on for the python extensions and VS code updates on restarts), it started to fail to run the script due to the Python file path having that space character.

Adding a launch file and surrounding the args value in a list did fix it for me.

I have a laptop with the project on it as well that I hadn't used since before this issue occurred. When I opened the project on it and ran the script, the terminal input appeared to have quotes around the python exe path. After I restarted the laptop and up to now, the exe path is no longer surrounded in quotes. So the same as my PC.

But, I didn't copy or screenshot the terminal that first time I started the laptop, so I might be misremembering the input.

PC VS Code Version: 1.97.2 (user setup) / Commit: e54c774e0add60467559eb0d1e229c6452cf8447
Laptop VS Code Version: 1.96.4 (user setup) / Commit: cd4ee3b1c348a13bafd8f9ad8060705f6d4b9cba

They both have the same versions for extensions:
Python: 2025.2.0
Python Debugger: 2025.4.1
Pylance: 2025.3.1

@fgiancane8
Copy link

Hello @MichaelCourter64 ,

Hi, I also had a problem with my python exe path having a space character and not being enclosed in quotes when running a script on my PC.

My project didn't have a launch file a couple weeks ago and was running the script fine. I would just have to occasionally specify how I wanted to run it when the command palette appeared: debug configuration, Python with arguments.

But now, without any apparent change (auto update is on for the python extensions and VS code updates on restarts), it started to fail to run the script due to the Python file path having that space character.

Adding a launch file and surrounding the args value in a list did fix it for me.

I think this is exactly connected to the same issue I am reporting, thanks for your contribution. Indeed I think that python interpreter path should be consistently quoted even if args are not surrounded in a list.

I have a laptop with the project on it as well that I hadn't used since before this issue occurred. When I opened the project on it and ran the script, the terminal input appeared to have quotes around the python exe path. After I restarted the laptop and up to now, the exe path is no longer surrounded in quotes. So the same as my PC.

But, I didn't copy or screenshot the terminal that first time I started the laptop, so I might be misremembering the input.

PC VS Code Version: 1.97.2 (user setup) / Commit: e54c774e0add60467559eb0d1e229c6452cf8447 Laptop VS Code Version: 1.96.4 (user setup) / Commit: cd4ee3b1c348a13bafd8f9ad8060705f6d4b9cba

They both have the same versions for extensions: Python: 2025.2.0 Python Debugger: 2025.4.1 Pylance: 2025.3.1

@eleanorjboyd eleanorjboyd modified the milestones: March 2025, April 2025 Mar 26, 2025
@eleanorjboyd eleanorjboyd modified the milestones: April 2025, May 2025 Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

4 participants