We have a set of command-line tools (AMPL with additional 'solvers') that we are going to deploy to a couple dozen computers. In order to run these from CMD without typing the full folder path, we need to add their folder path to the PATH Environment Variable in Windows. On our test computer I've create a folder in Program Files named AMPL, which contains the AMPL executable, and each of the additional solver executables are in subfolders within this folder, for example: Program Files > AMPL > xpress
Using PowerShell, I am able to add the AMPL folder to PATH. My issue arrises when I try to add one of the subfolders to PATH, the subfolder does not append to the list of path variables, it overwrites the previously added AMPL folder path.
Basically, the first part of the script runs, and it adds the AMPL folder to path, with this result:
C:\Windows\System32>pathPATH=C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;
...
C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;
[b]C:\Program Files\ampl[/b]
As the script continues onto the next folder, it's overwriting the previous:
C:\Windows\System32>pathPATH=C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;
...
C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;
[b]C:\Program Files\ampl\cplex[/b]
C:\Windows\System32>pathPATH=C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;
...
C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;
[b]C:\Program Files\ampl\xpress[/b]
Here is an example of the crude PowerShell script I'm using (Note: I'm very new to PowerShell, go easy on me)
$PATH = [Environment]::GetEnvironmentVariable("PATH")
$ampl_path = "C:\Program Files\ampl"
if( $PATH -notlike "*"+$ampl_path+"*" ){
[Environment]::SetEnvironmentVariable("PATH", "$PATH;$ampl_path", "Machine")
}
$cplex_path = "C:\Program Files\ampl\cplex"
if( $PATH -notlike "*"+$cplex_path+"*" ){
[Environment]::SetEnvironmentVariable("PATH", "$PATH;$cplex_path", "Machine")
}
$xpress_path = "C:\Program Files\ampl\xpress"
if( $PATH -notlike "*"+$xpress_path+"*" ){
[Environment]::SetEnvironmentVariable("PATH", "$PATH;$xpress_path", "Machine")
}
Is it possible to add the parent AMPL as well as the subfolders CPLEX and XPRESS to the path? Or should I just use the alternative method of dumping all the executables + associated files for these command line tools in one parent folder?