New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
\" doesn't work correctly in tasks.json #31722
Comments
Does it work if you move |
Nope, it has no change. |
@imba-tjd which shell are you using. Cmd, PowerShell or bash ? |
@dbaeumer powershell. |
@imba-tjd the setting to control the integrated shell to use is: |
@imba-tjd where is gcc installed ? |
@dbaeumer Actually, I installed Clang 4.0.1 pre-build version for windows x64 and MinGW-w64 7.1.0. And merge mingw into clang's directory. So the path of gcc is But personally I don't think this issue is connected to any external program or extensions. Because even I create this program: using System;
namespace PrintPara
{
class Program
{
static void Main(string[] args)
{
foreach (var item in args)
{
Console.WriteLine(item);
}
}
}
} And in tasks.json I write: {
"version": "2.0.0",
"tasks": [
{
"taskName": "Compile",
"command": ".\\printpara.exe",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"args": [
"\"${file}\""
]
}
]
} The result is still the same. It will split the argument by sapces and ignore quotes. |
This works for me with a simple dir command executed in cmd.exe. The example is tasks.json {
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "dir",
"type": "shell",
"command": "dir",
"args": [
"\"${file}\""
]
}
]
} Where $file is in a directory with space. However it doesn't work with PowerShell. @imba-tjd which shell are you using: cmd, PowerShell or same bash implementation? |
@imba-tjd just saw that you are using PowerShell. Need to understand what makes this different under PowerShell. |
You can configure the task to always run in cmd.exe since there the quoting with " works. Something like this: {
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "dir",
"type": "shell",
"options": {
"shell": {
"executable": "C:\\WINDOWS\\System32\\cmd.exe",
"args": [
"/d", "/c"
]
}
},
"command": "dir",
"args": [
"\"${file}\""
]
}
]
} |
@dbaeumer Yeah, configuring like that doesn't have this problem. So it's clear the issue exists, right? I know little about powershell and vs code so I can't help much. |
So I read about PowerShell and the right quoting for powershell is ' not ". Since we are open to the shell a user is using there is little VS Code can do to enforce the right quoting in case a argument contains spaces. So this works in PowerShell {
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "dir",
"type": "shell",
"command": "dir '${file}'",
"problemMatcher": []
}
]
} In your concrete example which calls gcc which I assume is an executable you could even do the following:
Please note that this uses a task of type process that mean VS Code does start gcc directly without starting PowerShell first. This bypasses shell interpretation which is always complicated to escape if arguments have spaces. I will keep the item open to see if there is more VS Code can do in terms of smartness or guiding the user to the rights quotes. |
@dbaeumer OK, I konw it. Thank you. |
Here is what we should do:
|
@dbaeumer Thank you. You are a hero |
I added support that you now can control the quoting in task 2.0. You can now for example write something like this:
In this case the task framework will quote the
which when executed in PowerShell prints |
Marking as dup of #45576 since it contains the change set to fix this. |
My OS: Windows LTSB 2015 x64
VS Code Version: 1.14.2
When the path doesn't contain a space, it can be compiled normally.
When the path contains a space, I try to use
\"
in tasks.json to make the path a string, but it is useless. Just the same as no\"
.Forget that red wavy line because I didn't configure c_cpp_properties.json.
The text was updated successfully, but these errors were encountered: