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
Terminal on Windows uses cmd /C
, this corrupts passed arguments
#145265
Comments
That said, why do you need to additionally quote your argument that contains |
Then why is this question transferred to I asked it in No matter how you write the argument in If you type the same command as put between
I just found out (somebody posted an image with Powershell as terminal) that the Powershell logic puts each argument between Can't the logic for Command Prompt be the same as for Powershell, but now put each argument between |
It should be filed in https://github.com/microsoft/vscode/ (with a reference to this one); I can't transfer it there automatically, unfortunately. And yes, escape rules differ from shell to shell, and VSCode has ad-hoc escape implementations for each of the supported ones, so a bug in one does not necessarily apply to any other. I'm not surprised that cmd in particular has these issues, as it has extremely convoluted escaping/quoting rules in general. |
I can transfer it over to vscode. |
cmd /C
, this corrupts passed argumentscmd /C
, this corrupts passed arguments
@karthiknadig be careful transferring issues as labels get auto created in the target repo |
Getting this perfectly correct is a losing game, but it should be closer to correct now. Please try it out in insiders |
Tried with
with this launch config
Running the
The quoting of the argument is better. But it still creates a file
The content of the file
The text But looking at the code But this is not done for Powershell, it just set and clear the variables. And if the environment is to messed up you just kill the current terminal and start a new one. Why not do the same for Remove the following lines:
|
I wonder why we don't use powershell by default? This is using the default "automation profile" from the terminal service, do you know @isidorn? I assume that changing it would break somebody's launch config though. |
I realized it does use powershell by default for me, do you have any terminal settings set @rioj7? |
@roblourens It doesn't matter what the default terminal config is. The problem is that using The solution is to remove the 4 lines. |
@weinand looks like you added this originally, do you know what the idea is behind wrapping the command with It's fine either way, I can escape the > with And @rioj7 I know it should be fixed for cmd, but was just curious because we should use powershell by default whenever possible. It seems like it should be using powershell unless you have set the automationProfile/automationShell setting, or if vscode can't find powershell. |
@roblourens I had to change the default terminal profile to cmd to get a cmd prompt. I looked at the blame and the commit for these lines and weinand moved this function from another file (4 years ago), and the I don't see a reason to hold on to these 4 lines by trying to escape some characters with |
@roblourens I do not know. @weinand might know better on what terminal profile we should use by default. |
IIRC, I'm using Please note: the ultimate goal of But may be that's a "losing game" (as already pointed out by @roblourens). |
Right, I will keep it then and escape characters inside that I opened #147709 for doing the same with powershell, either I can spawn a subshell in the same way or just clear environment variables manually. |
@weinand There is no reason to use If we just delete the Now rob is going to implement some workaround to Escape some characters because we have no reason to keep these 4 holy lines, but we keep them in. By the way the If I make a mess of the environment by using the If this local environment would be important then by now somebody using Powershell would have complained or he would have adjusted the launch config to set/reset all the environment variables he uses. Just deleting these 4 lines would make cmd the same as Powershell no need for some workarounds that could lead to other strange behavior if people use these escape characters in there arguments (regex expressions as arguments). |
The debug adapter can specify environment variables, python apparently doesn't support this with the terminal but others do and we have code to handle that. If you run one launch config with some environment variables, then another launch config, the vars from the first run shouldn't leak into the second. We could do that by killing the terminal too, but it's faster to keep it around. Either way, this is getting fixed, don't worry. |
debugpy does support specifying env vars, but the way we propagate them to the debuggee is different from most other adapter. We used to propagate env vars via the command line when doing So now, instead of that, we tell VSCode to spawn a separate launcher process with the default env, and then pass it the entire "launch" request to it as is via a socket backchannel; from there it reads env vars and sets them up before running the user code in a child process. I dunno if this makes any difference, though. Well, VSCode could drop the |
Another possibility is to let the user decide if it wants the sub-shell by adding a new argument to the launch config:
and the default value is
This way the 4 lines can be kept but the user decides if he wants it. Very few users have environment variables in the launch config and a few of them may need to create a sub-shell. Or
To let the user set the wrapping text. |
It is for bash but the first user with a problem passing regex arguments. Why is the btw. Only |
Good find, I'll fix that too. |
line 142 changed from
to
This results in a completely different regex:
On line 124 it is done correct, line 142 should be:
|
Damnit... thanks for checking |
I'm so confused what are you talking about? The official documentation say "If the debugger extension you are using can run the debug target in VS Code's Integrated Terminal (or an external terminal), you can try to pass the shell redirect syntax (for example, "<" or ">") as arguments." https://code.visualstudio.com/docs/editor/debugging#_redirect-inputoutput-tofrom-the-debug-target meaning that
should do D:\Python\Foo> d: && cd d:\Python\Foo && cmd /C "C:\Python310\python.exe c:\Users\name.vscode\extensions\ms-python.python-2022.6.0\pythonFiles\lib\python\debugpy\launcher 54849 -- d:\Python\Foo\main.py < out.txt " Like it had been before this update Not D:\Python\Foo> d: && cd d:\Python\Foo && cmd /C "C:\Python310\python.exe c:\Users\name.vscode\extensions\ms-python.python-2022.6.0\pythonFiles\lib\python\debugpy\launcher 54849 -- d:\Python\Foo\main.py ^< out.txt " Notice the If I type So how can I get back to being able to redirect standard input from args in the debugger? |
How do you change the debug terminal? It always defaults to cmd over powershell despite setting me setting the default terminal as power shell |
Environment data
Steps to reproduce:
Using the following Python script (
try-argparse.py
)with this
launch.json
Because I have a
>
in the argument I have to put the argument in double quotes.Executing the config results in the following command in the terminal:
The output in the terminal:
The
>
is gone (cmd
removes it), and I get extra"
characters.If I start the debugger with the following command (no
cmd /C "..."
):I can add the argument
--wait-for-client
if I want to attach to the debugger with VSC.I get in the terminal
The correct argument as set in the launch config.
What is the reason to use
cmd /C "debug launch command"
?And in this process the
"
in the argument gets transformed to"""
The text was updated successfully, but these errors were encountered: