VS-Code - How to Debug and pass Command Line Arguments via Launch Config
February 16, 2021
Introduction
In this post, I will take example for Python project. And how we can start debugging or launch a code file by passing command line arguments.
For this, you would need launch.json. If you have, just edit it as I will discuss in this post.
To create a new launch.json, click on Run -> Open Configuratio
or Run -> Add Configuration
Command Line Arguments
Lets take a look at launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: <Any_Name>",
"type": "python",
"request": "launch",
"program":"${file}"
"args": [
"-c", "/Users/xyz/config",
"-p", "2012"
]
}
]
}
In above configuration, I’m passing following command line parameters:
-c /Users/xyz/config -p 2012
Note: In above configuration, it will always launch current code file and tries to execute it or debug it. In this scenario, you will always open your main code file, and start debugging from there.
Or, if you don’t want to open main file again and again, see next section.
Provide Starting point code file for Debug
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Any_Name",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/app.py",
"args": [
"-c", "/Users/xyz/config",
"-p", "2012"
]
}
]
}
In above configuration, I’m telling visual studio code to execute app.py
file in my workspace folder.
Similar Posts
Moment.js - How to perform date relatedd arithmetic in javascript/NodeJs
Introduction In your backend and frontend projects, you always need to deal with…
Docker: unauthorized: incorrect username or password.
While running docker commands with some images, I started getting error: The…
How to run ElasticSearch cluster on Docker with Kibana on Linux
Introduction This post is about hosting ElasticSearch cluster on dockerised…
Drupal 8 - Advanced usage of Paragraphs module - Add nested set of fields and single Add more button (No Coding Required)
Introduction In my previous article, I explained How to have set of fields and…
Drupal 8: Bootstrap Sticky is not sticky in Drupal 8 - Solved
Bootstrap has a simple solution to have sticky blocks in your html. I’ve given a…
Latest Posts
Jenkins Pipeline with Jenkinsfile - How To Schedule Job on Cron and Not on Code Commit
Introduction In this post we will see following: How to schedule a job on cron…
How to Git Clone Another Repository from Jenkin Pipeline in Jenkinsfile
Introduction There are some cases, where I need another git repository while…
How to Fetch Multiple Credentials and Expose them in Environment using Jenkinsfile pipeline
Introduction In this post, we will see how to fetch multiple credentials and…
Jenkins Pipeline - How to run Automation on Different Environment (Dev/Stage/Prod), with Credentials
Introduction I have an automation script, that I want to run on different…
Jenkinsfile - How to Create UI Form Text fields, Drop-down and Run for Different Conditions
Introduction I had to write a CICD system for one of our project. I had to…
Java Log4j Logger - Programmatically Initialize JSON logger with customized keys in json logs
Introduction Java log4j has many ways to initialize and append the desired…