首页 > 解决方案 > 为什么在执行带有 VS 代码任务的 Windows 批处理文件时看不到任何输出

问题描述

我第一次尝试 VS 代码任务,我创建了一个test.bat文件

echo hello 

和这个tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "test",
            "type": "shell",
            "command": "cmd /c c:\\test\\test.bat"
        }
    ]
}

运行任务时,它似乎执行它,但为什么我看不到 echo 的任何输出(即“hello”)?

在此处输入图像描述

标签: visual-studio-code

解决方案


参数不应该发布在 中command,所以你的任务应该是这样的:

{
  "command": "cmd",
  "args": ["/c", "c:\\test\\test.bat]
}

但是,由于 Microsoft 添加了自动检测,因此以下内容也应该有效:

{
  "type": "shell",
  "command": ""c:\\test\\test.bat"
}

有关详细信息,请参阅自定义任务文档


推荐阅读