vscode1 Min Read

VS-Code - How to Debug and pass Command Line Arguments via Launch Config

Gorav Singal

February 16, 2021

TL;DR

Configure the args array in VS Code's launch.json to pass command line arguments when debugging a Python (or other language) project.

VS-Code - How to Debug and pass Command Line Arguments via Launch Config

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.

Share

Related Posts

VS-Code - How to put vscode executable in system path and how to open source code directly in vscode

VS-Code - How to put vscode executable in system path and how to open source code directly in vscode

Introduction VS code is an excellent free IDE for maany types of programming…

Microsoft Visual Studio Code - Must-have extensions for Developers

Microsoft Visual Studio Code - Must-have extensions for Developers

Visual Studio Code is one of the awesome developer tools by Microsoft. Let’s…

How to solve java issue - could not load main class - Visual Studio Code

How to solve java issue - could not load main class - Visual Studio Code

Assuming you have a java project and is using Visual Studio Code as IDE. All of…

Visual Studio Code - How to associate file extension to a known programming language

Visual Studio Code - How to associate file extension to a known programming language

Problem Statement I have a drupal module, where there is a file of extension…

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Latest Posts

AI Video Generation in 2025 — Models, Costs, and How to Build a Cost-Effective Pipeline

AI Video Generation in 2025 — Models, Costs, and How to Build a Cost-Effective Pipeline

AI video generation went from “cool demo” to “usable in production” in 2024-202…

AI Models in 2025 — Cost, Capabilities, and Which One to Use

AI Models in 2025 — Cost, Capabilities, and Which One to Use

Choosing the right AI model is one of the most impactful decisions you’ll make…

AI Image Generation in 2025 — Models, Costs, and How to Optimize Spend

AI Image Generation in 2025 — Models, Costs, and How to Optimize Spend

Generating one image with AI costs between $0.002 and $0.12. That might sound…

AI Coding Assistants in 2025 — Every Tool Compared, and Which One to Actually Use

AI Coding Assistants in 2025 — Every Tool Compared, and Which One to Actually Use

Two years ago, AI coding meant one thing: GitHub Copilot autocompleting your…

AI Agents Demystified — It's Just Automation With a Better Brain

AI Agents Demystified — It's Just Automation With a Better Brain

Let’s cut through the noise. If you read Twitter or LinkedIn, you’d think “AI…

Supply Chain Security — Protecting Your Software Pipeline

Supply Chain Security — Protecting Your Software Pipeline

In 2024, a single malicious contributor nearly compromised every Linux system on…