Question

I know that in a normal tcl script environment variables can be accessed like this:

global env
puts "User: $env(USER)"

set env(IOFILE) "somefile.txt"

but this doesn't seem to work within an ITCL class method. How can I get and set environment variables inside ITCL class code?

Was it helpful?

Solution

Itcl does complex things with variable discovery, but you can override the trickiness by giving the fully-qualified name of the variable (the global command will bind the last component of the name in the local scope to the named variable). Thus:

global ::env  ;# <<<<<< Note this <<<<<<

puts "User: $env(USER)"
set env(FOO) "bar"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top