question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Certain strings set in the launch.json "args" will not be passed to python as arguments

See original GitHub issue

Environment data

  • VS Code version: 1.47.2
  • Extension version (available under the Extensions sidebar): 2020.7.94776
  • OS and version: macOS Catalina 10.15.5
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.2 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): virtualenv
  • Relevant/affected Python packages and their versions: N/A
  • Relevant/affected Python-related VS Code extensions and their versions: N/A
  • Value of the python.languageServer setting: Jedi

Expected behaviour

Putting “\s” anywhere in an argument in the “args” list of the launch.json file will then pass that argument “\s” to the python file I’m debugging

Actual behaviour

Instead, “” is passed as an argument to the python file

  • Using “\s” resulted in “” being passed,
  • Using “\s” resulted in “\s” being passed.
  • Using “\\s” resulted in “\” being passed

Steps to reproduce & more detail:

  1. Create a python file
  2. Put a new item launch.json’s “arg” list, which contains a backslash, and then some letter, like “\s” or “\w”
  3. Debug the python file

You will notice that instead of “\s” being passed as an argument in the terminal, “” is passed (Just two double quotes)

I have also tried this with double backslashes. Using the same steps as above, but instead, I put “\s” in the “args” list. This also didn’t work, and I saw that “\s” was passed to my python file in the terminal. I added another slash, but “\\s” that only resulted in “\” being passed to my python file.

  • Using one slash resulted in “” being passed,
  • Using two slashes resulted in “\s” being passed.
  • Using three slashes resulted in “\” being passed.

All I want is for “\s” to be passed as an argument to my python file.

Logs

In launch.json:

"args": [
	"\s"
]

In Python Debug console: (Generated by the vscode-python extension)

cd /PATH/TO/DIR/src ; env /PATH/TO/PYTHON/python /Users/USERNAME/.vscode/extensions/ms-python.python-2020.7.94776/pythonFiles/lib/python/debugpy/launcher 50448 -- /PATH/TO/PYTHONFILE/foo.py ""

In launch.json:

"args": [
	"\\s"
]

In Python Debug console: (Generated by the vscode-python extension)

cd /PATH/TO/DIR/src ; env /PATH/TO/PYTHON/python /Users/USERNAME/.vscode/extensions/ms-python.python-2020.7.94776/pythonFiles/lib/python/debugpy/launcher 50448 -- /PATH/TO/PYTHONFILE/foo.py \\s

In launch.json:

"args": [
	"\\\s"
]

In Python Debug console: (Generated by the vscode-python extension)

cd /PATH/TO/DIR/src ; env /PATH/TO/PYTHON/python /Users/USERNAME/.vscode/extensions/ms-python.python-2020.7.94776/pythonFiles/lib/python/debugpy/launcher 50448 -- /PATH/TO/PYTHONFILE/foo.py \\

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
int19hcommented, Jul 23, 2020

For bash at least, double quotes don’t disable escaping - only single quotes do. So echo \\s is equivalent to echo "\\s" and to echo '\s'.

Other special symbols like $, (), and & are a bit different - there are some scenarios in which you want them to not be escaped (so that shell can perform variable and subshell expansion, for example), and others when you do want to pass them verbatim to the app.

So, the debugger now allows you to control that by specifying "argsExpansion": "none" in your launch.json. The default setting is to enable shell expansion, because that’s what the extension was doing before the setting was added, and we didn’t want to break people with pre-existing launch.json configs relying on that behavior.

1reaction
int19hcommented, Jul 23, 2020

The correct syntax is this one:

"args": ["\\s"]

Because JSON itself treats \ as a special character, so you need to escape it if you intend to use it verbatim.

The reason why the command line VSCode generates contains \\s, is because it is in turn escaping it for bash, which also requires backslashes to be escaped. If you do print(sys.argv[1]) from inside Python, it should have the value that you expect.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot get VS Code to pass arguments to Python from launch ...
json file by using the debug button to the right I have circled here. The only way I can get my arguments to...
Read more >
Debugging configurations for Python apps in Visual Studio Code
When no configuration has been set, you'll be given a list of debugging options. Here, you can select the appropriate option to quickly...
Read more >
launch.vs.json schema reference (C++) - Microsoft Learn
When there's no project or solution file, you can specify custom build tasks and launch parameters through JSON configuration files.
Read more >
VS-Code - How to Debug and pass Command Line ...
In this post, I will take example for Python project. And how we can start debugging or launch a code file by passing...
Read more >
Run/debug configurations | PyCharm Documentation - JetBrains
Set the run/debug configuration parameters. In the Before launch section, define whether you want to perform any specific actions before launching the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found