0

My below .bat file add MySQL's bin directory to system PATH though the old PATH values get duplicated.

@echo off

set pathMySQL=C:\xampp\mysql
set p=%%

setx MYSQL_HOME "%pathMySQL%"
setx PATH "%p%MYSQL_HOME%p%\bin;%PATH%"

I expect the PATH value after this execution to be as below.

%MYSQL_HOME%\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin

The actual value is as below - paths are repeated twice

%MYSQL_HOME%\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;

What I did wrong? How can I get over this?

Nam G VU
  • 33,193
  • 69
  • 233
  • 372

1 Answers1

-1

The duplicated values in my system PATH are caused by how %PATH% is built up in Windows 7.

%PATH% = P1 + P2

P1 = PATH variable for machine

P2 = PATH variable for user

Clearing P2 to be empty will fix my issue.

Nam G VU
  • 33,193
  • 69
  • 233
  • 372
  • ... except that that moves the user's PATH settings into the system variable, adversely affecting every other user on the machine. Use `pathman` instead of `setx` if at all possible, or use a more powerful language (powershell, vbscript, or cscript would do) to manipulate the registry entries directly. – Harry Johnston Jan 20 '15 at 04:52
  • mod parent (*Harry Johnston) up. – mnemotronic Dec 06 '15 at 15:50
  • @mnemotronic, how does clearing P2 move the user's path settings into the system variable? – johny why Feb 11 '16 at 18:22