VS Code 外部.batファイルを起動

VS Code メニューから[表示]→[コマンドパレット]→「task」と入力→[タスク:タスクの構成]→[テンプレートから task.json を生成]→[others 任意の外部コマンドを実行する例]

「task.json」に以下を入力。

{
    "version": "2.0.0",
    "tasks": 
    [
        {
            "label": "Save All",
            "command": "saveAll",
            "type": "shell",
        },
        {
            "label": "Bat",
            "command": "start .bat",
            "type": "shell",
            "options": { "cwd": "${fileDirname}" },
        },
        {
            "label": "Exit",
            "command": "exit",
            "type": "shell",
        },
        {
            "label": "Build",
            "dependsOn": ["Save All", "Bat", "Exit"]
        },
    ],
}

続いてショッートカットキーの作成もしましょう。
まずVS Codeのメニューから[表示]→[コマンドパレット]と押し、出て来た検索ボックスに「キーボード」と入力して
「基本設定:キーボード ショートカットを開く(JSON)」を押してください。


出て来た「keybindings.json」に以下の内容を記入

[
    {
        "key": "F9",
        "command": "workbench.action.tasks.runTask",
        "args": "Build",
    },
]

これで作業中のフォルダから開いたソースの上で「F9」キーを押すと、自動で開いているすべてのファイルを上書き保存した後「.bat(任意名)」がターミナルに実行されます。

One response... add one

Leave a Reply