我在网上没有找到答案,所以我在这里提问。 我实际上是 Visual Studio Code 的开发人员,例如 Python 等语言。 如果我运行代码,它总是会打开一个新终端,这样我就可以更快地打开许多终端,但每次关闭它们都很痛苦。 可以在当前打开的终端中运行代码而不写我自己的“python 文件名”吗?
最佳答案
要在 VSCode 中将项目作为任务运行,您所需要做的就是创建一个 .vscode/tasks.json
文件,如下所示。以下任务将在集成终端中打开:
{
// 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
},
}
]
}
在同一终端中运行的关键焦点是 "panel": "shared"
行。这将在同一终端中运行该命令。
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.
关于python - Visual Studio Code 在同一终端中运行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55125120/