How to run a command in Visual Studio Code with launch.json

前端 未结 4 2078
刺人心
刺人心 2020-12-03 00:38

Is there a way to execute an ssh command when debugging a project with .vscode/launch.json?

For example: ssh -i xxxxx.

O

4条回答
  •  旧巷少年郎
    2020-12-03 01:08

    You can define a task in your tasks.json file and specify that as the preLaunchTask in your launch.json and the task will be executed before debugging begins.

    Example:

    In tasks.json:

    For version 0.1.0:

    {
        "version": "0.1.0",
        "tasks": [{
            "taskName": "echotest",
            "command": "echo", // Could be any other shell command
            "args": ["test"],
            "isShellCommand": true
        }]
    }
    

    For version 2.0.0 (newer and recommended):

    {
        "version": "2.0.0",
        "tasks": [{
            "label": "echotest",
            "command": "echo", // Could be any other shell command
            "args": ["test"],
            "type": "shell"
        }]
    }
    

    In launch.json:

    {
        "configurations": [
            {
                // ...
                "preLaunchTask": "echotest", // The name of the task defined above
                // ...
            }
        ]   
    }
    

    Tasks documentation: https://code.visualstudio.com/docs/editor/tasks

    Launch configuration: https://code.visualstudio.com/docs/editor/debugging#_launch-configurations

提交回复
热议问题