【问题标题】:How can I pass the arguments from a Visual Studio Code task.json to a g++ command when the command includes a space当命令包含空格时,如何将参数从 Visual Studio Code task.json 传递给 g++ 命令
【发布时间】:2018-11-08 13:58:06
【问题描述】:

我有一个Visual Studio Code tasks.json 文件可以通过g++ 运行C++ 文件:

{
"version": "2.0.0",
"tasks": [
    {
        "label": "echo",
        "type": "shell",
        "command": "g++",
        "args": [
            "-I ~/vcpkg/installed/x64-osx/include/",
            "test.cpp"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
]
}

问题是生成的命令> Executing task: g++ '-I ~/vcpkg/installed/x64-osx/include/' test.cpp < 有单引号,所以这不起作用。

我看了here 并尝试了这个:

{
"version": "2.0.0",
"tasks": [
    {
        "label": "echo",
        "type": "shell",
        "command": "g++",
        "args": [
            {
              "value": "-I ~/vcpkg/installed/x64-osx/include/",
              "quoting": "escape"
            },
            "test.cpp"
          ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
]
}

问题是生成的命令> Executing task: g++ -I\ ~/vcpkg/installed/x64-osx/include/ test.cpp < 使用escape 所以有一个\

如何生成所需的命令:

g++ -I ~/vcpkg/installed/x64-osx/include/ test.cpp

【问题讨论】:

    标签: json visual-studio-code intellisense


    【解决方案1】:

    添加单引号是因为参数中有空格。只需将“-I”和“~/vcpkg/installed/x64-osx/include/”分开的参数。

    "args": [
        "-I", "~/vcpkg/installed/x64-osx/include/",
        "test.cpp"
    ]
    

    【讨论】:

      猜你喜欢
      • 2020-03-29
      • 1970-01-01
      • 2010-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-17
      • 1970-01-01
      相关资源
      最近更新 更多