问题
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