'Passing spaces in arguments for Visual Studio Pro 2019

I am trying to debug a command line program inside Visual Studio. I am sharing my configuration with another machine using Box. The paths I am passing have spaces in them and I haven't been successful in escaping the spaces so that instead of 3 arguments I get 9. This is the relevant section from the original launch.vs.json.

{
  "type": "default",
  "project": "CMakeLists.txt",
  "projectTarget": "dispatcher.exe (src\\dispatcher\\dispatcher.exe)",
  "name": "dispatcher.exe (src\\dispatcher\\dispatcher.exe)",
  "args": [
    "C:\\Users\\212434537\\Box Sync\\Edge Agent\\srasku-windows.json",
    "C:\\Users\\212434537\\Box Sync\\Edge Agent\\static.json",
    "C:\\Users\\212434537\\Box Sync\\Edge Agent\\dynamic.json"
  ]
}

None of these work.

"\"C:\\Users\\212434537\\Box Sync\\Edge Agent\\srasku-windows.json\""
"\\"C:\\Users\\212434537\\Box Sync\\Edge Agent\\srasku-windows.json\\""
"\\\"C:\\Users\\212434537\\Box Sync\\Edge Agent\\srasku-windows.json\\\""
"\\\\"C:\\Users\\212434537\\Box Sync\\Edge Agent\\srasku-windows.json\\\\""

How can I escape my spaces so that each argument is passed as a single argument instead of three. Note: I saw this question but it didn't solve my problem.



Solution 1:[1]

It turns out you need to surround the spaces with singly-escaped double-quotes:

Here is the resultant section:

   {
      "type": "default",
      "project": "CMakeLists.txt",
      "projectTarget": "dispatcher.exe (src\\dispatcher\\dispatcher.exe)",
      "name": "dispatcher.exe (src\\dispatcher\\dispatcher.exe)",
      "currentDir": "C:\\Users\\212434537\\source\\Edge-Agent",
      "args": [
        "C:\\Users\\212434537\\Box\" \"Sync\\Edge\" \"Agent\\srasku-windows.json",
        "C:\\Users\\212434537\\Box\" \"Sync\\Edge\" \"Agent\\static.json",
        "C:\\Users\\212434537\\Box\" \"Sync\\Edge\" \"Agent\\dynamic.json"
      ]
    }

Solution 2:[2]

A simple workaround for this, is just to include the entire path in quotes, such as:

"C:\Users\212434537\Box Sync\Edge Agent\dynamic.json"

So, the escaped json becomes:

"\"C:\\Users\\212434537\\Box Sync\\Edge Agent\\dynamic.json\""

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stephen Rasku
Solution 2 Jahmic