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

VSCode启动自动执行命令报错:返回值非字符串,如何修复?

问题描述

在VSCode的tasks.json中配置了以下任务:

{
    "label": "closealleditorsingroup",
    "type": "shell",
    "command": "${input:closealleditorsingroup}",
    "runOptions": {
        "runOn": "folderOpen"
    }
},

对应的inputs配置:

"inputs":[
    {
        "type": "command",
         "id": "closealleditorsingroup",
        "command": "workbench.action.closeEditorsInGroup"
    }
]

通过folder>code .打开文件夹时,VSCode会自动运行该任务,能成功关闭上一会话的所有编辑器,但随后弹出错误:

Cannot substitute input variable 'closealleditorsingroup' because command 'workbench.action.closeEditorsInGroup' did not return a result of type string.

修复方法
  • 改用command类型任务替代shell类型
    原配置的核心问题是shell类型任务要求command字段为可执行字符串,但workbench.action.closeEditorsInGroup是VSCode内部命令,执行后不会返回字符串结果,导致变量替换失败。修改任务配置如下:

    {
        "label": "closealleditorsingroup",
        "type": "command",
        "command": "workbench.action.closeEditorsInGroup",
        "runOptions": {
            "runOn": "folderOpen"
        }
    }
    

    同时删除对应的inputs配置,因为已无需通过input中转调用命令。

  • 效果验证
    修改后重新通过code .打开文件夹,VSCode会自动执行关闭编辑器组内所有文件的操作,且不会再弹出错误提示。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 00:33:10