Windows Batch. Append to PATH Environment Variable, when It Contains Spaces

5

2

I want to add some binaries to path for my console session and I'm doing it like so

if not defined WIXTOOLKIT_IN_PATH (
    set WIXTOOLKIT_IN_PATH=1
    set MY_PATH=%~dp0..\tools\wix
    SET PATH=%MY_PATH%;%PATH%
)

But it happens so, that my PATH contains spaces and I'm getting message \Skype\Phone\ was unexpected at this time. with set PATH command echoed

                                SET PATH=;C:\Python34\;C:\Python34\Scripts;C:\ProgramData\
Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\Sy
stem32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Pr
ogram Files (x86)\Skype\Phone\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Pr
ogram Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Mic
rosoft SDKs\TypeScript\1.0\;C:\Program Files (x86)\CMake\bin

I'm sure, that this is the trivial situation, but I could not find any solution. How can I fix it?

Vasilly.Prokopyev

Posted 2015-07-13T21:25:45.217

Reputation: 183

1SET "PATH=%MY_PATH%;%PATH%" – DavidPostill – 2015-07-13T21:34:06.337

@DavidPostill like a charm – Vasilly.Prokopyev – 2015-07-13T21:50:44.123

Answers

5

My PATH contains spaces and I'm getting message ... was unexpected at this time

You need to quote the arguments to set.

Replace:

SET PATH=%MY_PATH%;%PATH%

With:

SET "PATH=%MY_PATH%;%PATH%"

Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • set - Display, set, or remove CMD environment variables. Changes made with SET will remain only for the duration of the current CMD session.

DavidPostill

Posted 2015-07-13T21:25:45.217

Reputation: 118 938