Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a run button in Visual Studio Code?

To give you an example of what i mean with "run button": Once you install Python extension in Visual Studio Code, you can press a button in the top right of the screen, and then VSC automatically executes a command in a shell running Python on the active .py file.

Given this example, I'd like to know how to make a button for VSC that automatically creates a new terminal, executes a command which i would insert in the making of the button and nothing else, and of course the terminal shall not disappear after giving the desired output.

like image 719
Luxo Avatar asked May 08 '26 10:05

Luxo


2 Answers

Install the Task Runner extension. Now, every task you add to tasks.json will be displayed as a button, in the 'Task runner' panel (which is normally on the same tab as the file explorer).

Here's a decent tasks.json template:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "COMMAND NAME",
            "type": "shell",
            "command": "YOUR COMMAND HERE",
            "presentation": {"echo": true, "reveal": "always", "focus": false, "panel": "shared", "showReuseMessage": false, "clear": true},
        },
        // More tasks here, if you need them.
    ]
}

Put this file in your project directory, in a directory called .vscode. Open the project directory with "File" -> "Open Folder".

like image 187
HolyBlackCat Avatar answered May 10 '26 22:05

HolyBlackCat


Install Code Runner extension in VS Code

enter image description here

like image 35
Saurabh Avatar answered May 10 '26 23:05

Saurabh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!