如何将批处理脚本的输出重定向到 Visual Studio Code 的集成终端?

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

我有一个 Visual Studio Code 任务,它使用以下代码执行批处理脚本:

{
   "version": "2.0.0",
   "tasks": [
      {
         "label": "Run batch file",
         "type": "shell",
         "windows": {
            "command": "${workspaceFolder}\\run_script.bat",
            "args": [
               "arg1",
               "arg2"
            ]
         },
         "presentation": {
            "focus": true,
            "clear": true,
            "panel": "shared"
         }
      }
   ]
}

当我运行任务时,会打开一个新控制台,输出会出现一秒钟,然后控制台关闭。

如何在不打开任何额外控制台的情况下将输出重定向到 Visual Studio Code 的集成终端?

更新1

这是我的 VS Code 设置.json:

{
    "http.proxy": "[A URL I REMOVED ONLY FOR THIS POST]",
    "window.zoomLevel": 1,
    "files.autoSave": "afterDelay",
    "explorer.confirmDelete": false,
    "git.enableSmartCommit": true,
    "git.confirmSync": false,
    "workbench.startupEditor": "none",
    "diffEditor.ignoreTrimWhitespace": false,
    "editor.accessibilitySupport": "off",
    "git.ignoreRebaseWarning": true,
    "autopep8.args": [
        "--ignore=E501"
    ],
    "diffEditor.renderSideBySide": false
}

更新2

我正在试验,其他批处理文件输出显示在集成终端中。甚至在“run_script.bat”文件中输出 echo 命令。所以这个问题特定于我的批处理文件中的某一特定行:

start /w "" "%path_to_exe%" /arg1 /arg2

我认为这是打开一个单独的控制台并在那里输出的行。 如何将其输出重定向到 VS Code 的集成终端?

谢谢。

visual-studio-code batch-file terminal console vscode-tasks
1个回答
0
投票

正如我在更新中所写,该问题与任务的配置方式无关。这是我的批处理脚本中的第

start /w "" "%path_to_exe%" /arg1 /arg2
行。

阅读了

start
命令的文档后,我添加了 /B 选项。

/B 启动应用程序而不创建新窗口。在这种情况下 Ctrl-C 将被忽略 - 将 Ctrl-Break 作为唯一的方法 中断应用程序。

线路现在是:

start /b /w "" "%path_to_exe%" /arg1 /arg2

输出会自动重定向到 VS Code 的集成终端。

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