The easiest way is probably to use the Tcl script to write a batch file with a known name that contains the environment variable setting, say env.bat
:
set f [open env.bat w]
puts $f "SET FOO=BAR"
close $f
Then you can make your real batch file just CALL
that to get the environment variable definition from it:
CALL env.bat
This is the method that is going to be easiest to make work in a way that is non-surprising. It's also going to be pretty easy to debug, since you can always look at env.bat
in a text editor and figure out if the things in it are sensible. (I'm assuming that everything is run in the same directory and that the code has permission to write there; that's definitely the easiest way to do it. It's possible to write a temporary file somewhere else and pass the name around, but that's rather more complex to make function correctly.)