我的系统路径是:
C:\Users\angus\algs4\java\bin;C:\binaryTools\SMLNJ\bin\;C:\Program Files (x86)\Python36-32\Scripts\;C:\Program Files (x86)\Python36-32\;C:\Program Files\Java\jdk1.8.0_66\bin;C:\ProgramData\Oracle\Java\javapath;C:\binaryTools;C:\Program Files (x86)\ActiveState Komodo IDE 8\;C:\PHP\;C:\Program Files (x86)\Haskell\bin;C:\Program Files (x86)\Haskell Platform\2012.4.0.0\lib\extralibs\bin;C:\Program Files (x86)\Haskell Platform\2012.4.0.0\bin;C:\MinGW\msys\1.0\bin;C:\MinGW\bin;C:\Program Files\Java\jdk1.8.0_66\bin;c:\Program Files (x86)\AMD APP\bin\x86_64;c:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Services\IPT\;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;C:\Program Files\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\TortoiseHg\;C:\Program Files (x86)\Haskell Platform\2012.4.0.0\mingw\bin;C:\Python33;C:\Python33\Scripts;C:\Program Files\Microsoft Platform SDK\Bin\.;C:\Program Files\Microsoft Platform SDK\Bin\WinNT\.;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Python27;C:\Python27\Scripts;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Collaborator Client;C:\Program Files\doxygen\bin;C:\Program Files\TortoiseGit\bin;
我正在尝试使用脚本更新注册表项(系统路径)但是出现了一个奇怪的错误:
>myscript.cmd
\Python36-32\Scripts\ was unexpected at this time.
如何解决脚本错误?
这是脚本:
echo off
SET PROGPATH=C:\dell\mypath
for /f "tokens=2*" %%a in ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path') do set "SysPath=%%~b"
echo system path is: %SysPath%
echo %SysPath%>tmppath.txt
echo %PATH% | findstr /i %PROGPATH%
if %ERRORLEVEL% EQU 1 (
echo %PROGPATH% path not found in system path
REM we now add to syspath and then write back to registry
set UPDATEDPATH=%PROGPATH%;%SysPath%
REM we now just write UPDATEDPATH back to registry
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /f /v "Path" /t REG_SZ /d "%UPDATEDPATH%"
echo %PROGPATH% should now be added to the system path
) else (
echo %PROGPATH% already in path
)
问题在于:echo%PATH%| grep%PROGPATH%
只要有
,就会收到错误C:\Program Files (x86)\Java\jre1.8.0_45\bin;
或类似的东西。
即(x86)\ J或(x86)\ P等
那么如何解决这个问题?
被问到更多细节。所以在这里。
在运行脚本之前,我的环境是这样的:
键名:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
路径键具有值:
C:\Users\angus\algs4\java\bin;C:\binaryTools\SMLNJ\bin\;C:\Program Files (x86)\Python36-32\Scripts\;C:\Program Files (x86)\Python36-32\;C:\Program Files\Java\jdk1.8.0_66\bin;C:\ProgramData\Oracle\Java\javapath;C:\binaryTools;C:\Program Files (x86)\ActiveState Komodo IDE 8\;C:\PHP\;C:\Program Files (x86)\Haskell\bin;C:\Program Files (x86)\Haskell Platform\2012.4.0.0\lib\extralibs\bin;C:\Program Files (x86)\Haskell Platform\2012.4.0.0\bin;C:\MinGW\msys\1.0\bin;C:\MinGW\bin;C:\Program Files\Java\jdk1.8.0_66\bin;c:\Program Files (x86)\AMD APP\bin\x86_64;c:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Services\IPT\;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;C:\Program Files\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\TortoiseHg\;C:\Program Files (x86)\Haskell Platform\2012.4.0.0\mingw\bin;C:\Python33;C:\Python33\Scripts;C:\Program Files\Microsoft Platform SDK\Bin\.;C:\Program Files\Microsoft Platform SDK\Bin\WinNT\.;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Python27;C:\Python27\Scripts;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Collaborator Client;C:\Program Files\doxygen\bin;C:\Program Files\TortoiseGit\bin;
>echo %PATH%
C:\Users\angus\algs4\java\bin;C:\binaryTools\SMLNJ\bin\;C:\Program Files (x86)\Python36-32\Scripts\;C:\Program Files (x86)\Python36-32\;C:\Program Files\Java\jdk1.8.0_66\bin;C:\ProgramData\Oracle\Java\javapath;C:\binaryTools;C:\Program Files (x86)\ActiveState Komodo IDE 8\;C:\PHP\;C:\Program Files (x86)\Haskell\bin;C:\Program Files (x86)\Haskell Platform\2012.4.0.0\lib\extralibs\bin;C:\Program Files (x86)\Haskell Platform\2012.4.0.0\bin;C:\MinGW\msys\1.0\bin;C:\MinGW\bin;C:\Program Files\Java\jdk1.8.0_66\bin;c:\Program Files (x86)\AMD APP\bin\x86_64;c:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Services\IPT\;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;C:\Program Files\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\TortoiseHg\;C:\Program Files (x86)\Haskell Platform\2012.4.0.0\mingw\bin;C:\Python33;C:\Python33\Scripts;C:\Program Files\Microsoft Platform SDK\Bin\.;C:\Program Files\Microsoft Platform SDK\Bin\WinNT\.;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Python27;C:\Python27\Scripts;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Collaborator Client;C:\Program Files\doxygen\bin;C:\Program Files\TortoiseGit\bin;C:\Users\angus\algs4\bin;C:\Users\angus\algs4\java\bin;C:\Users\angus\AppData\Roaming\cabal\bin;C:\Program Files\Microsoft Platform SDK\Bin\.;C:\Program Files\Microsoft Platform SDK\Bin\WinNT\.;C:\binaryTools\emacs-24.5-bin-i686-mingw32\bin;C:\windows;C:\windows\system32;C:\Users\angus\AppData\Roaming\Dashlane\4.7.1.28771\bin\Firefox_Extension\{442718d9-475e-452a-b3e1-fb1ee16b8e9f}\components;C:\Users\angus\AppData\Roaming\Dashlane\4.7.1.28771\ucrt
现在,如果我运行批处理文件内容,我将其命名为path3.cmd,我得到:
>path3.cmd
\Python36-32\Scripts\ was unexpected at this time.
>
尝试
echo %PATH% | findstr /i /c:"%PROGPATH%"
或
echo "%PATH%" | findstr /i /c:"%PROGPATH%"
没有区别。
这个错误似乎在这一行:
set UPDATEDPATH=%PROGPATH%;%SysPath%