Reputation: 61
I didn't find the answer on Internet so I'm asking here. I'm actually dev on Visual Studio Code some language like Python for example. If I'm running the code, it's always opening a new terminal so I can have faster a lot of terminal opened and it's a pain to close them every time. It is possible to run the code in the current terminal opened without write my self "python filename" ?
Upvotes: 4
Views: 8443
Reputation: 61
Here my task file for anyone wants to launch a python file easier :
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run Script",
"command": "python",
"presentation": {
"panel": "shared",
"reveal": "always",
"focus": true
},
"args": [
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Use the shortcut CTRL+SHIFT+B for build the task and do the same shortcut when you want to rebuild :)
Upvotes: -2
Reputation: 447
To run a project in VSCode as a task, all you need to do is create a .vscode/tasks.json
file like so. The following task will open in the integrated terminal:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run shell command",
"type": "shell",
"command": "echo 'Hello world!'",
"group": "test",
"presentation": {
"panel": "shared",
"reveal": "always",
"focus": true
},
}
]
}
Key focus to running in the same terminal is the "panel": "shared"
line. This runs the command in the same terminal.
Note: this task is untested as I do not have access to a VSCode instance at the moment.
Here is some more information on VSCode tasks. Here is a Python task tutorial by VSCode. More information on task output behaviour.
Upvotes: 3