Skip to content
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

Quotes removed from parameter when calling os.spawn() #263

Closed
jpvolkmann opened this issue May 26, 2020 · 4 comments
Closed

Quotes removed from parameter when calling os.spawn() #263

jpvolkmann opened this issue May 26, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@jpvolkmann
Copy link

jpvolkmann commented May 26, 2020

When passing arguments to a new process the quotes are removed in the monkey-patched version os.spawn of debugpy in debugpy/src/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py in function patch_args().

It seems to be possible to avoid this by setting apply_arg_patching to False, but I don't know how to pass this parameter to the debugger in VSCode

Environment:

Windows 10
VSCode 1.45.1

Example:

C-Program to call:

#include <iostream>
int main(int argc, char* argv[])
{
	for (int i = 0; i < argc; i++)
	{
		std::cout << "Argument " << i << ": " << argv[i] << "\n";
	}
	std::cout << "Press key to continue ...";
	std::cin.get();
}

Python Program:

import os

program = r'PrintArgV.exe'
params = [
    program,
    '/nologo',
    r'"-IC:\Program Files (x86)\Python37-32\include"',
    r'"My Dir/My great program.c"'
]

print(os.spawnv)
os.spawnv(os.P_WAIT, program, params)

Output without debugger:

<built-in function spawnv>
Argument 0: PrintArgV.exe
Argument 1: /nologo
Argument 2: -IC:\Program Files (x86)\Python37-32\include
Argument 3: My Dir/My great program.c
Press key to continue ...

Output with debugger:

<function create_spawnv.<locals>.new_spawnv at 0x039E8078>
Argument 0: PrintArgV.exe
Argument 1: /nologo
Argument 2: -IC:\Program
Argument 3: Files
Argument 4: (x86)\Python37-32\include
Argument 5: My
Argument 6: Dir/My
Argument 7: great
Argument 8: program.c
Press key to continue ...
@karthiknadig karthiknadig added the enhancement New feature or request label May 26, 2020
@karthiknadig
Copy link
Member

@fabioz, @int19h Probably we should add something like argsExpansion property that we have to skip shell expansion for this as well? May be argsSkipPatching.

@int19h
Copy link
Contributor

int19h commented May 27, 2020

I believe the problem here is that the quoting logic is not entirely correct. On Unix, it's easier because it's already dealing with separated arguments, but on Windows, it only has the original command line as a single string, so basically has to replicate the argument parsing logic that's used by the apps.

There's no single right answer there, because they can and do handle it differently; and maybe we'll need a parameter to distinguish those. But this looks like a very straightforward case that should "just work".

Nor can it really skip parsing the args entirely, because it needs the result to inject Python and pydevd in there.

@fabioz
Copy link
Collaborator

fabioz commented May 27, 2020

I'll take a look at it.

@fabioz fabioz self-assigned this May 27, 2020
@fabioz
Copy link
Collaborator

fabioz commented Jun 3, 2020

This was actually an oversight on the case where patching was not actually needed (the first thing we do is unquote args to deal with them and in the case where we do patch the args, everything works because we apply quotes back when needed, but on the case where the patch wasn't needed in the first place because it's not calling a new python executable it was returning the unquoted version instead of the original args).

@fabioz fabioz closed this as completed in fad8ae6 Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants