问题
i am adding a line in a .bat file look like this:
path %~dp0;%PATH%
But this message is shown:
\common was unexpected at this time.
Let me show you the path.
PATH=C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program File
s (x86)\Common Files\Microsoft Shared\Windows Live;c:\Program Files (x86)\AMD AP
P\bin\x86_64;c:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windo
ws;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Progr
am Files (x86)\ATI Technologies\ATI.ACE\Core-Static\;C:\Program Files (x86)\Sony
\VAIO Startup Setting Tool;;C:\Program Files (x86)\Windows Live\Shared;C:\Progra
m Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\P
rogram Files (x86)\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\C
alibre2\
This is the path. The path i want to add (%~dp0) is:
C:\Users\Workspace\Desktop\Files\Programming\GoogleSearch\
This is important for me.
Thank you.
回答1:
You could try setx as shown in this answer....
https://serverfault.com/questions/88363/how-do-i-set-the-global-path-environment-in-a-batch-file
回答2:
In this particular case the problematic character is closing parenthesis ' ) '
Instead of this:
path %~dp0;%PATH%
use this:
path %~dp0;%PATH:)=^)%
The above syntax will tell DOS to replace all parenthesis ) in the PATH variable with their escaped versions ^)
回答3:
It seem to be the issue described in this article. You probably use command language construction with parentheses in your batch-file.
回答4:
Related to this post (tested)
- Remove
%PATH%variable in yourset PATH=..string. - Like
set PATH=C:\Path\to\fileinstead ofset PATH=%PATH%;C:\Path\to\file
来源:https://stackoverflow.com/questions/21749095/cmd-path-error-common-was-unexpected-at-this-time