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

标签 python terminal visual-studio-code

我在网上没有找到答案,所以我在这里提问。 我实际上是 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/

相关文章:

Python 似乎永远不会启动循环

Python从字典中的列表中获取值

c++ - 我如何获取字符串输入,将其用每个空格隔开,并将每个单词放入数组,然后对单个单词进行检查?

visual-studio-code - VS代码: create custom snippet/shortcut

java - VS Code Java 调试器在某些代码行处卡住

visual-studio-code - 在 Visual Studio Code 之上开发应用程序

python - 计算相似向量的频率

python - Kivy 登录屏幕和弹出窗口出错

blackberry - 默认 SSH/Telnet 终端大小

macos - IntelliJ 无法从终端打开