You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Visual Studio Code终端中隐藏程序运行前缀命令文本?

解决VS Code运行Python程序时终端显示命令行的问题

以下是几个能让终端只显示程序输出、同时保留用户输入功能的方法:

方法一:自定义任务(tasks.json)

  1. 打开命令面板(按下Ctrl+Shift+P),输入Tasks: Configure Task,选择Create tasks.json file from template,再选Others。
  2. 将生成的tasks.json内容替换为以下配置:
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run Python Script",
            "type": "shell",
            "command": "python -u \"${file}\"",
            "args": [],
            "presentation": {
                "echo": false,  // 不显示执行的命令
                "reveal": "always",
                "focus": true,
                "panel": "shared",
                "showReuseMessage": false,
                "clear": true  // 每次运行前清空终端(可选)
            },
            "problemMatcher": []
        }
    ]
}
  1. 保存后,按下Ctrl+Shift+B选择Run Python Script运行当前脚本,终端只会显示程序的输出和输入提示,不会显示执行的命令行。

方法二:修改调试配置(launch.json)

如果习惯用调试按钮运行程序:

  1. 打开调试面板(Ctrl+Shift+D),点击"create a launch.json file",选择Python环境。
  2. 在launch.json的配置项中添加或修改以下内容:
{
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen",
    "env": {"PYTHONUNBUFFERED": "1"},
    "presentation": {
        "echo": false
    }
}
  1. 保存后点击调试按钮运行,终端将只显示程序的输出和输入交互内容。

补充说明

  • 两种方法都保留了终端的输入功能,解决了Output面板无法输入的问题。
  • 若不需要每次运行前清空终端,可将配置里的"clear": true删除或改为false。

内容的提问来源于stack exchange,提问作者Mohammad Masood

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 10:57:04