Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set system environmental variable

Status
Not open for further replies.

MatthewMiller

Technical User
Dec 1, 2004
1
DE
I'm new to TCL, but would like to write a short script to change a windows environment variable. If I write

puts $env(VARIABLE)

I can correctly read the variable, however when I write

set $env(VARIABLE) VALUE

then go to the control panel (windows xp) the variable that I wanted to change has not been updated.

Here is some sample code that shoul summerize my problem

% puts $env(VARIABLE)
user1
(bin) 2 % set $env(VARIABLE) user2
user2
(bin) 3 % puts $env(VARIABLE)
user1
(bin) 4 %

If anyone can help please do, sample code would be great
 
When you change or set an environment variable (an element of the Tcl array, env()) inside Tcl, you are only setting the variable for the Tcl session (within the Tcl shell). This is actually a feature. To change the variable for the base OS, you need to do it outside of the Tcl shell. That is, from your script, you need to run something like "exec set VARIABLE value".

Bob Rashkin
rrashkin@csc.com
 
Even that is only good for the process/thread you are
exec'ing it in of course.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top