在 Visual Studio Code 中,如何在 launch.json 中传递参数

Jon*_*enn 14 command-line-arguments node.js visual-studio-code

在 Visual Studio Code 中,在launch.json启动我正在编写的应用程序的文件中,如何添加命令行参数?

Nav*_*had 39

我通过这种方式为python程序传递参数,它可能适用于nodejs:

{
    "type": "node",
    "request": "launch",
    "name": "Debug App",
    "program": "${workspaceFolder}/main.js",
    "args": ["--arg1", "value1", "--arg2", "value2"]
}
Run Code Online (Sandbox Code Playgroud)

  • 在 Python 上非常适合我。谢谢 (2认同)

Jon*_*enn 23

文档中所述,您需要使用该args属性。例如

{
    "type": "node",
    "request": "launch",
    "name": "Debug App",
    "program": "${workspaceFolder}/main.js",
    "args": ["arg1", "arg2", "arg3"]
}
Run Code Online (Sandbox Code Playgroud)

  • 只是为了澄清 args 数组, `"args": ["key=value", "key=value"]` (13认同)