Nam G VU
Nam G VU

Reputation: 35384

Path system variable gets duplicated values when update via setx command

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?

Upvotes: 0

Views: 2223

Answers (1)

Nam G VU
Nam G VU

Reputation: 35384

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.

Upvotes: 0

Related Questions