97

In Visual Studio Code, in the launch.json file that launches the app I'm writing, how do I add command line arguments?

1

3 Answers 3

118

As described in the documentation, you need to use the args attribute. E.g.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Debug App",
            "program": "${workspaceFolder}/main.js",
            "args": ["arg1", "arg2", "arg3"]
        }
    ]
}
Sign up to request clarification or add additional context in comments.

8 Comments

@eigenfield have you tried filing a bug report with Visual Studio Code or Kotlin?
just to clarify args array, "args": ["key=value", "key=value"]
@AwaisNasir is that suggestion for Kotlin? Or in general? In practice, I've used simple strings and not key-value pairs.
@JonathanBenn I don't know about kotlin, thats the general solution, for me key value pair solution worked and not simple strings
If I run this as is, I get an error: launch: property 'cwd' is missing or empty. I had to manually add this line to the launch.json to get it to work ``` "cwd": "${workspaceFolder}" ```
|
47

I pass arguments by this way for the python program, it may work for nodejs:

{
    "type": "node",
    "request": "launch",
    "name": "Debug App",
    "program": "${workspaceFolder}/main.js",
    "args": ["--arg1", "value1", "--arg2", "value2"]
}

3 Comments

Works perfectly for me on Python. Thanks
Still work perfectly for me as well :D
It worked. Thanks
0

In settings.json in the .vscode folder you can pass an env file.

settings.json

{
    "python.testing.pytestArgs": [
        "."
    ],
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,
    "python.envFile": "${workspaceFolder}/env"

}

and the env file

FLASK_ENV=test

1 Comment

settings.json and launch.json are different files for different purposes. And yes, launch.json exists on macOS too, it is just not created out of the blue, it is created when a run configuration is created.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.