Visual Studio Code在同一终端中运行代码

问题描述 投票:0回答:2

我没有在互联网上找到答案所以我在这里问。我实际上是开发Visual Studio Code的一些语言,例如Python。如果我正在运行代码,它总是打开一个新的终端,这样我可以更快地打开很多终端,每次关闭它们都很痛苦。有可能在打开的当前终端中运行代码而不写我自己的“python filename”吗?

python terminal visual-studio-code
2个回答
0
投票

要在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"线。这在同一终端中运行命令。

注意:此任务未经测试,因为此刻我无法访问VSCode实例。

Here is some more information on VSCode tasks. Here is a Python task tutorial by VSCode. More information on task output behaviour.


0
投票

在这里,任何人都希望更轻松地启动python文件的任务文件:

{
    // 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
            }
        }
    ]
}

使用快捷键CTRL + SHIFT + B构建任务,并在想要重建时执行相同的快捷方式:)

© www.soinside.com 2019 - 2024. All rights reserved.