当命令包含空格时,如何将参数从Visual Studio Code task.json传递给g ++命令 [英] How can I pass the arguments from a Visual Studio Code task.json to a g++ command when the command includes a space

查看:171
本文介绍了当命令包含空格时,如何将参数从Visual Studio Code task.json传递给g ++命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

问题在于生成的命令> Executing task: g++ '-I ~/vcpkg/installed/x64-osx/include/' test.cpp <具有单引号,因此将无法使用.

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

问题在于生成的命令> Executing task: g++ -I\ ~/vcpkg/installed/x64-osx/include/ test.cpp <使用escape,因此具有\.

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

如何生成所需的命令:

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

推荐答案

添加单引号是因为参数中有空格.只需将"-I"和〜/vcpkg/installed/x64-osx/include/"分开设置为args.

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

这篇关于当命令包含空格时,如何将参数从Visual Studio Code task.json传递给g ++命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆