Brent
Brent

Reputation: 4886

Using visual studio code and running tasks where path to .exe contains a space

I am following the walkthrough from the microsoft docs for using typescript in a vs code project. When I try and run the build task, the terminal comes up with

Executing task: c:\whatever\my path with spaces\Projects\ProjectName\node_modules.bin\tsc.cmd -p "c:\whatever\my path with spaces\Projects\ProjectName\tsconfig.json"

and the error

'c:\whatever\my' is not recognized as an internal or external command,

That is, the space in the folder name is confusing the task runner. I need something like

call "c:\whatever\my path with spaces\Projects\ProjectName\node_modules\.bin\tsc.cmd" -p "c:\whatever\my path with spaces\Projects\ProjectName\tsconfig.json"

How do I set up VS Code so the terminal recieves an input it can interpret with spaces in the directory name? Thank you

current tasks.json:

"version": "2.0.0",
"tasks": [
    {
        "type": "typescript",
        "tsconfig": "tsconfig.json",
        "problemMatcher": [
            "$tsc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
]

Upvotes: 12

Views: 6811

Answers (3)

Thomas Kintzel
Thomas Kintzel

Reputation: 74

You should use quotation marks \" (slash + quotation mark) for the entire command as in

"command": "\"c:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe\"",

or if using backslashes

 "command": "\"c:\\tools\\my tool folder\\test.exe\"",

Please note that there are to quotations marks at the end of the command (one for json string and one for defined a path including spaces)

Upvotes: 1

abdella
abdella

Reputation: 754

To deal with path includes space, we need to surround the path with a single quotation marks.

So the command "$tsc" should be surrounded with a single quotation mark as "'$tsc'" check this stackoverflow

Upvotes: 1

danigeri
danigeri

Reputation: 29

Try using ''-s to escape the string containing the spaces:

  • in terminal: c:\whatever\'my path with spaces'\Projects\ProjectName\tsconfig.json
  • in .json: "command": "c:\\whatever\\'my path with spaces'\\Projects\\ProjectName\\tsconfig.json"

Upvotes: 2

Related Questions