在 VsCode 中按键执行 bat 文件 [英] Execute a bat file on keypress in VsCode

查看:37
本文介绍了在 VsCode 中按键执行 bat 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 vulkan 编写着色器,必须将其编译为 spir-v.我有一个非常好的批处理文件,它将使用 GLSlangvalidator 完成并为我构建着色器.我正在尝试使用按键在 VsCode 中运行我的批处理文件,以便我可以检查我的代码是否有错误并构建它.我有以下内容:

I'm writing shaders for vulkan, which have to be compiled into spir-v. I have a very nice batch file that will go through and build my shaders for me using the GLSlangvalidator. I'm trying to get a keypress to run my batch file in VsCode so I can check my code for errors and so that it is built. I have the following:

    {
    "key": "f5",
    "label": "build",
    "type": "shell",
    "command": "workbench.action.terminal.sendSequence",
    "args" : {"text": ".\compile.bat"},
    "presentation" : {
        "reveal": "always"
    }

这几乎有效 - 但我仍然必须专注于内置终端面板并按回车键.当然有一种方法可以执行命令,而不仅仅是输入字符串?谢谢!

This nearly works - but I still have to focus on the inbuilt terminal panel and hit enter. Surely there is a way to execute a command, rather than to just input the string? Thanks!

推荐答案

tasks.json 中,创建一个任务来运行 .bat.像这样:

In tasks.json, create a task to run the .bat. Something like this:

{
    "label": "MY_TASK",
    "type": "shell",
    "command": "MY_BAT_FILE.bat",
    "presentation": {"echo": true, "reveal": "always", "focus": false, "panel": "shared", "showReuseMessage": false, "clear": true},
    "group": {"kind": "build", "isDefault": true},
},

然后,使用 Tasks: Run Build Task 热键(默认为 CtrlShiftB).

Then, use the Tasks: Run Build Task hotkey (CtrlShiftB by default).

您可以有多个这样的任务.

You can have more than one such task.

至多一个任务可以有 "isDefault": trueCtrlShiftB应该运行.

At most one task can have "isDefault": true, the one that CtrlShiftB should run.

您可以为这些任务分配自定义热键,方法是将以下内容添加到您的 keybindings.json:

You can assign custom hotkeys to those tasks, by adding following to your keybindings.json:

{"key": "f5", "command": "workbench.action.tasks.runTask", "args": "MY_TASK"},
//       ^~ key                                                     ^~~~~~~ task name

这篇关于在 VsCode 中按键执行 bat 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆