Visual Studio Code 在同一个终端中运行代码 [英] Visual Studio Code run code in the same terminal

查看:51
本文介绍了Visual Studio Code 在同一个终端中运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有在互联网上找到答案,所以我在这里问.我实际上是 Visual Studio Code 的开发人员,例如 Python 之类的某种语言.如果我正在运行代码,它总是会打开一个新终端,所以我可以更快地打开很多终端,每次关闭它们都很痛苦.是否可以在当前打开的终端中运行代码而不写我自己的python 文件名"?

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" ?

推荐答案

要将项目作为任务在 VSCode 中运行,您需要做的就是创建一个 .vscode/tasks.json 文件,例如所以.以下任务将在集成终端中打开:

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
            },
        }
    ]
}

在同一终端中运行的重点是 "panel": "shared" 行.这将在同一终端中运行命令.

Key focus to running in the same terminal is the "panel": "shared" line. This runs the command in the same terminal.

注意:此任务未经测试,因为我目前无权访问 VSCode 实例.

Note: this task is untested as I do not have access to a VSCode instance at the moment.

这里有一些关于 VSCode 任务的更多信息.这里是 VSCode 的 Python 任务教程.有关任务输出行为的更多信息.

这篇关于Visual Studio Code 在同一个终端中运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆