【问题标题】:VSCode task wraps command in ' ' quotes breaking args on multi-line commandsVSCode 任务将命令包装在 ' ' 引号中,在多行命令中打破 args
【发布时间】:2018-04-10 12:19:13
【问题描述】:

我正在尝试创建一个运行带有一些参数的命令的 VSCode 任务。

"tasks": [
    {
        "label": "Execute in Max",
        "type": "shell",
        "command": "cd\\; C:\\MXSPyCOM.exe",
        "args": [
            "-f",
            "'${file}'"
        ],
        "problemMatcher": []
    }
]

然后我得到错误:

& : 模块 'cd' 无法加载。有关更多信息,请运行“Import-Module cd”。 在行:1 字符:3 + & 'cd\; C:\MXSPyCOM.exe' -f 'c:\Users\ ... + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (cd\; C:\MXSPyCOM.exe:String) [], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoLoadModule

我相当肯定问题在于它试图执行的命令:'cd\; C:\MXSPyCOM.exe' -f 'c:\Users\ 主命令块由于某种原因被单引号括起来,这使得 shell 认为它是一个命令,当它是多个命令时。

这在过去没有发生过,几个月前我最后一次使用这个命令时,它工作得很好。知道有什么问题吗?

【问题讨论】:

  • 如果我注释掉参数,shell 执行得很好。我也可以通过标准 cmd 或 PS 控制台运行带有 args 的 exe,没有任何问题

标签: visual-studio-code task


【解决方案1】:

是的,直到 1.21.0 vscode 在 args 中有空格时才发出警告,最新版本在命令和 args 中有空格时用单引号括起来。 只需打破命令以使其中没有空格,或者通过

"command": "cd\\;C:\\MXSPyCOM.exe",

"command": "cd\\;",
"args": [
            "C:\\MXSPyCOM.exe",
            ...

当没有这样的选项(例如将命令传递给 ssh 会话)时,我所做的是:

"command": "ssh",
"args": [
            "host_name",
            "bash",
            "-c",
            "'\"",
            "cd /some_dir;",
            ...
            "\"'"
        ],

快速而肮脏的解决方法是根本不使用args 字段,并在command 中拥有完整的命令。

另一种解决方案是编写自己的脚本,然后从 tasks.json 中调用它们

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 2021-03-12
    • 2021-09-12
    • 1970-01-01
    相关资源
    最近更新 更多