I want to specify arguments in my launch.json
file for debugging. I know I can do the following:
"args": ["--arg1", "value", "--arg2"]
However, I have a very long list of arguments that is formatted as a space-delimited string. Something like this: "--arg1 value --arg2"
. I tried specifying:
"args": ["--arg1 value --arg2"]
But that didn't work. Right now my workflow is to take the string of arguments, run it through a Python script that changes the string into a list and copy paste it in my launch.json
file. Is there a better way to do this?
args - arguments passed to the program to debug.
A workaround is to have your script ask for the command-line arguments (in the internal Visual Studio Code console). Then just set up Visual Studio Code to always pass in the --interactive argument, and your script will always ask for arguments (with history!) even as you set breakpoints.
To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line. They will be passed to the program via the argv array.
Mind that providing arguments in launch.json
works like described until you need key value args.
For example, the command
$ python main.py --verbose --name Test
has to be coded inside the launch.json arguments line like this:
"args": ["--verbose", "--name=Test"],
Find a nearly hidden hint in the "Watson" example in Python debug configurations in Visual Studio Code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With