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!

environment variable 1

Status
Not open for further replies.

klois

Technical User
Oct 22, 2003
5
CH
I try to set an environment variable in a tk script with the following command:
set env(my_env_variable) "test"
but when I check in my system environment variable she doesn't exist, I'm under win2k and use wish83
Can you help me with that, thanks
 
It worked for me correctly, and I'm running on Windows 2000.

But keep in mind that setting an environment variable in a Tcl application is effective only for that particular application while it is running, as well as for any other processes that it might spawn. This is a standard security policy, enforced by the operating system (on Unix as well as Windows).

If you actually need to set a persistent environment variable, you'll need to go to the "Advanced" tab of the Windows "System Properties" dialog, click on the "Environment Variables" button, and set it there.

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Yes, what I want is to set a persistent environment variable to be able to use it with other application and I prefer made this automaticaly but if I can't...
 
I find a way with the registry command, see below:
package require registry
registry set HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\Session Manager\\Environment\\my_env_variable test
but I still have a problem with the blank space between Session and Manager because of this blank it creates a registry key Manager\\Environment\\my_env_variable with the value test in HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\Session root.
Is there anybody who knows how to solve that
thanks
 
This is basic Tcl syntax: Tcl is a whitespace-separated language. Unless you quote characters, spaces and/or tabs delimit argument (or "word") boundaries. Tcl has 2 types of quoting characters:
[ul][li]Curly braces ([tt]{}[/tt]) group together characters into a single argument, but prevent the Tcl interpreter from performing any substitutions on the contents before executing the command. Basically, it's a case of "what you see is what you get."[/li]

[li]Double quotes ([tt]""[/tt]) group together characters into a single argument, but allow the Tcl interpreter to perform substitution on its contents before executing the command. Thus, the interpreter can perform:

[ul][li][tt]$[/tt] variable substitutions[/li][li][tt]\[/tt] "escape" substitutions[/li][li][tt][ignore][][/ignore][/tt] command substitutions[/li][/ul][/ul]So (ignoring bad line breaks that might occur in this post), in your situation, you could do either:

Code:
registry set "HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\Session Manager\\Environment\\my_env_variable" test

or

Code:
registry set {HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment\my_env_variable} test


- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Thanks for your answer but it steal doesn't work, (I try this yesterday and try one time today), I have the following message when I write with {} or with "":

% package require registry
1.0
% registry set {HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session ManagerEnvironment\my_env_variable} test
wrong # args: should be "registry set keyName ?valueName data ?type??"

Perhaps I steal miss something?
 
Sorry, I didn't take close enough of a look at your code. You don't want to include the name of the environment variable as part of the key. It's actually considered a value in this case, and the string you want to assign to the variable is considered the data for that value. Thus, the proper command to accomplish what you want (once again ignoring any bad line break that might occur in this posting) is:

Code:
registry set {HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment} my_env_variable test

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Thanks very much, it works fine now
Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top