vscode调试后如何自动关闭任务终端

时间:2020-02-17 04:17:58

标签: c

launch.json
...
"preLaunchTask": "startDebug",
"postDebugTask": "closeOpenOCDTerminal"

tasks.json
{
"version": "2.0.0",
"tasks": [
    {
        "label": "startDebug",
        "type": "shell",
        "command": "make -j4; openocd -f interface/cmsis-dap.cfg -c 'transport select swd' -f target/stm32f1x.cfg",
        "isBackground": true,
        "problemMatcher": {
            "pattern": {
                "regexp": "."
            },
            "background": {
                "activeOnStart": true,
                "beginsPattern": ".",
                "endsPattern": "."
            }
        }
    },
    {
        "label": "closeOpenOCDTerminal",
        "type": "process",
        "command":[
            "${command:workbench.action.tasks.terminate}",
            // "${command:workbench.action.acceptSelectedQuickOpenItem}" //invalid
         ]
    }
]
}

OpenOCD服务不会像make命令那样自动结束,仅取决于关闭终端或执行Ctrl +C。 调试后如何自动关闭任务终端? 或在任务终端中自动执行Ctrl + C命令以结束Openocd服务。 当前使用的closeOpenOCDTerminal方法需要手动单击弹出列表。

1 个答案:

答案 0 :(得分:0)

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "start",
            "type": "shell",
            "command": "make -j4; openocd -f interface/cmsis-dap.cfg -c 'transport select swd' -f target/stm32f1x.cfg",
            "isBackground": true,
            "problemMatcher": {
                "pattern": {
                    "regexp": "."
                },
                "background": {
                    "activeOnStart": true,
                    "beginsPattern": ".",
                    "endsPattern": "."
                }
            }
        },
        {
            "label": "stop",
            "command": "echo ${input:terminate}",
            "type": "shell",
        }
    ],
    "inputs": [
        {
          "id": "terminate",
          "type": "command",
          "command": "workbench.action.tasks.terminate",
          "args": "terminateAll"
        }
    ]
}

此示例恰好关闭了任务终端。