How to set Windows environment variable from Tcl script

Juergen

I have a Tcl script which generates some value which I like to store in a Windows environment variable. I know that this cannot be done directly from within my script.

What I am planning to do is to output the value to stderr:

puts stderr $var

How do I use the stderr channel to set a environment variable in the calling batch file?

Is there a more convenient way to set a environment variable from a Tcl script?

Donal Fellows

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.)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to set Jenkins environment variable from script

From Dev

How to get the environment variable set by a bash script from inside a python script?

From Dev

Setting environment variables from within TCL script

From Dev

How to set `screen` environment variable from bash?

From Dev

How to fix the error "vncserver: The HOME environment variable is not set" - run a Python script from PHP on behalf of the user?

From Dev

set environment variable from sh script in systemd service file

From Dev

How do I set the path to the build.xml file in a Jenkins ant build from an environment variable on Windows

From Dev

How do I set an environment variable on Windows 10, which was generated from GitHub?

From Dev

How to set environment variable before running script inside hooks/install?

From Dev

How to set environment variable before running script inside hooks/install?

From Dev

How do I set an environment variable in the shell to be result of python script?

From Dev

How to export environment variable set in perl script to batch shell?

From Dev

Passing a Variable from Python script to tcl shell

From Dev

How to set a variable with an environment variable read from a text file

From Dev

How to set the PATH environment variable in Jenkins configuration on Windows?

From Dev

How to set PATH environment variable in ProcessBuilder java in windows

From Dev

How to set PATH environment variable in batch file only once on Windows?

From Dev

How can I set up the python environment variable on Windows 7?

From Dev

How to set an environment variable in Ubuntu and Windows and store it securely?

From Dev

How to set PATH environment variable in batch file only once on Windows?

From Dev

Environment variable not set, from Netbeans

From Dev

set environment variable from batch

From Dev

Environment variable not set, from Netbeans

From Dev

How to Export Environment Variable From Script in PHP Docker Entrypoint

From Dev

How do I set a Machine environment variable from a Chocolatey package?

From Dev

How to set a global environment variable from Inno Setup installer?

From Dev

How to check if environment variable is set from C program

From Dev

How do I set a environment variable from a powershell command?

From Dev

How to set shell environment variable from autotools .am file?

Related Related

  1. 1

    How to set Jenkins environment variable from script

  2. 2

    How to get the environment variable set by a bash script from inside a python script?

  3. 3

    Setting environment variables from within TCL script

  4. 4

    How to set `screen` environment variable from bash?

  5. 5

    How to fix the error "vncserver: The HOME environment variable is not set" - run a Python script from PHP on behalf of the user?

  6. 6

    set environment variable from sh script in systemd service file

  7. 7

    How do I set the path to the build.xml file in a Jenkins ant build from an environment variable on Windows

  8. 8

    How do I set an environment variable on Windows 10, which was generated from GitHub?

  9. 9

    How to set environment variable before running script inside hooks/install?

  10. 10

    How to set environment variable before running script inside hooks/install?

  11. 11

    How do I set an environment variable in the shell to be result of python script?

  12. 12

    How to export environment variable set in perl script to batch shell?

  13. 13

    Passing a Variable from Python script to tcl shell

  14. 14

    How to set a variable with an environment variable read from a text file

  15. 15

    How to set the PATH environment variable in Jenkins configuration on Windows?

  16. 16

    How to set PATH environment variable in ProcessBuilder java in windows

  17. 17

    How to set PATH environment variable in batch file only once on Windows?

  18. 18

    How can I set up the python environment variable on Windows 7?

  19. 19

    How to set an environment variable in Ubuntu and Windows and store it securely?

  20. 20

    How to set PATH environment variable in batch file only once on Windows?

  21. 21

    Environment variable not set, from Netbeans

  22. 22

    set environment variable from batch

  23. 23

    Environment variable not set, from Netbeans

  24. 24

    How to Export Environment Variable From Script in PHP Docker Entrypoint

  25. 25

    How do I set a Machine environment variable from a Chocolatey package?

  26. 26

    How to set a global environment variable from Inno Setup installer?

  27. 27

    How to check if environment variable is set from C program

  28. 28

    How do I set a environment variable from a powershell command?

  29. 29

    How to set shell environment variable from autotools .am file?

HotTag

Archive