How can I pass the arguments from a Visual Studio Code task.json to a g++ command when the command includes a space

爱⌒轻易说出口 提交于 2020-01-06 08:16:38

问题


I have a Visual Studio Code tasks.json file to run a C++ file via g++:

{
"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
        }
    }
]
}

The problem is the resulting command > Executing task: g++ '-I ~/vcpkg/installed/x64-osx/include/' test.cpp < has single quotes so that won't work.

I took a look here and tried this:

{
"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
        }
    }
]
}

The problem is the resulting command> Executing task: g++ -I\ ~/vcpkg/installed/x64-osx/include/ test.cpp < uses escape so has a \.

How can I generate the desired command:

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


回答1:


The single quotes are added because there is a space in the argument. Just make "-I" and "~/vcpkg/installed/x64-osx/include/" separate args.

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


来源:https://stackoverflow.com/questions/53209218/how-can-i-pass-the-arguments-from-a-visual-studio-code-task-json-to-a-g-comman

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!