Do local var assignments in batch files have priority over global env vars even for programs ?

  • Thread starter Thread starter Michael Walsh
  • Start date Start date
M

Michael Walsh

Assume the system PATH variable is set in Control Panel->System globally as:

PATH=D:\aaa\bin;D:\bbb\bin

Then I start a DOS batch file mytest.bat with the following content:

set PATH=D:\bbb\bin;%PATH%

Note that the folder D:\bbb\bin has now priority over D:\aaa\bin!

Now I start from within the same batch file a program:

myprog.exe param1 param2

Does this program now use (if necessary) programs from the aaa\bin or bbb\bin
directory?

If the programs uses the globally defined vars and ignores the just done assignments:
Is there a way to create a local, temporarily changed environment for the run of a certain program otherwise?

Michael
 
Michael Walsh said:
Assume the system PATH variable is set in Control Panel->System globally
as:

PATH=D:\aaa\bin;D:\bbb\bin

Then I start a DOS batch file mytest.bat with the following content:

set PATH=D:\bbb\bin;%PATH%

Note that the folder D:\bbb\bin has now priority over D:\aaa\bin!

Now I start from within the same batch file a program:

myprog.exe param1 param2

Does this program now use (if necessary) programs from the aaa\bin or
bbb\bin
directory?

If the programs uses the globally defined vars and ignores the just done
assignments:
Is there a way to create a local, temporarily changed environment for the
run of a certain program otherwise?

Michael

When you launch a Command Prompt then all changes to environmental
variables will be effective within this Command Prompt but not outside.
The same applies to your type of batch file, even if you launch it from the
Start / Run button:
@echo off
set PATH=D:\bbb\bin;%PATH%
"c:\Some Folder\myprog.exe" param1 param2
 
Yes, when you run your batch file that will overwrite the variable for that
cmd session and has no affect on any other cmd window or on Windows itself.
Your example does not alter the path for future batch files nor will any
other program running be affected. Just that command window.
 
Michael said:
Assume the system PATH variable is set in Control Panel->System
globally as:

PATH=D:\aaa\bin;D:\bbb\bin

Then I start a DOS batch file mytest.bat with the following content:

set PATH=D:\bbb\bin;%PATH%

Note that the folder D:\bbb\bin has now priority over D:\aaa\bin!

Now I start from within the same batch file a program:

myprog.exe param1 param2

Does this program now use (if necessary) programs from the aaa\bin or
bbb\bin
directory?

If the system can't find the program in bbb\bin, it'll use the one from
aaa\bin

If the programs uses the globally defined vars and ignores the just
done assignments:
Is there a way to create a local, temporarily changed environment for
the run of a certain program otherwise?

Change the name of one of the programs?
 
Michael Walsh said:
Assume the system PATH variable is set in Control Panel->System globally
as:

PATH=D:\aaa\bin;D:\bbb\bin

Then I start a DOS batch file mytest.bat with the following content:

set PATH=D:\bbb\bin;%PATH%

Note that the folder D:\bbb\bin has now priority over D:\aaa\bin!

Now I start from within the same batch file a program:

myprog.exe param1 param2

Does this program now use (if necessary) programs from the aaa\bin or
bbb\bin
directory?

If the programs uses the globally defined vars and ignores the just done
assignments:
Is there a way to create a local, temporarily changed environment for the
run of a certain program otherwise?

Michael

When you launch a Command Prompt then all changes to environmental
variables will be effective within this Command Prompt but not outside.
The same applies to your type of batch file, even if you launch it from the
Start / Run button:
@echo off
set PATH=D:\bbb\bin;%PATH%
"c:\Some Folder\myprog.exe" param1 param2
 
Back
Top