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

查看:263
本文介绍了在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"
    }

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

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": "build",
    "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 热键(默认情况下为 Ctrl Shift B ).br>它将运行标有"isDefault":true 的任务.

Then, use the Tasks: Run Build Task hotkey (CtrlShiftB by default).
It will run the task marked with "isDefault": true.

如果您想要多个热键,则可以在 keybindings.json 中添加如下所示的条目:

If you want more than one hotkey, you can instead add entries like following to your keybindings.json:

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

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

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