当命令包含空格时,如何将参数从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
问题描述
我有一个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屋!