Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using exec with set command

27 views
Skip to first unread message

The Potters

unread,
Mar 16, 2011, 11:21:11 AM3/16/11
to
I am trying to set a Windows environment variable from a Tcl script.
I understand the Tcl command below will only change the variable for
the current process and its sub-processes.
set env(NEW_VAR) whatever
Since I want to set the environment variable for all processes I tried
the Tcl command below in my script
exec set NEW_VAR=whatever
The result was the error "couldn't execute "set": no such file or
directory". My next attempt was to create the batch file
"set_env_var.bat" with one the one line below:
set %1=%2
I tested this batch file with the command
set_env_var.bat NEW_VAR whatever
The result was that the NEW_VAR environment variable was set to equal
whatever. I put the lines in my Tcl script
exec set_env_var.bat NEW_VAR whatever
(Yes it's a kludge.). The line didn't cause an error, but it didn't
seem to set the NEW_VAR environment variable either.

Is there a way to make this work? I am using Active 8.5.8.1 (free
version) on Windows XP.

Thanks.
Tom

Gerald W. Lester

unread,
Mar 16, 2011, 11:54:25 AM3/16/11
to
On 3/16/11 10:21 AM, The Potters wrote:
> I am trying to set a Windows environment variable from a Tcl script.
> I understand the Tcl command below will only change the variable for
> the current process and its sub-processes. ...

That is not a Tcl limitation -- it is how the world works.

On Windows you may be able to do something with TWAPI to set the environment
variable for other processes.

Also you can use the registry to set system wide environment variables that
processes will pick up when they start up.

--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+------------------------------------------------------------------------+

Ralf Fassel

unread,
Mar 17, 2011, 7:04:37 AM3/17/11
to
* The Potters <tpot...@gmail.com>

| The result was that the NEW_VAR environment variable was set to equal
| whatever. I put the lines in my Tcl script exec set_env_var.bat
| NEW_VAR whatever (Yes it's a kludge.). The line didn't cause an
| error, but it didn't seem to set the NEW_VAR environment variable
| either.

It sets the environment variable in the called process (the .bat) and
all its subprocesses. It does not affect the environment of the
desktop, or the environment which you get initially after login.

On Windows, the environment for the current user is stored in the
registry. In order for a running process to permanently change the
environment, change the value in the registry:

http://support.microsoft.com/kb/104011/en-us

HTH
R'

0 new messages