0

I am working on TCL script that will open another tcl file and I want to get value of variable from second opened file and use it in the first file.

Two file abc.tcl and xyz.tcl abc.tcl opens file xyz.tcl and reads value of variable and use it in abc.tcl.

1 Answer 1

1

If xyz.tcl sets a global variable, abc.tcl will be able to see it if it used source to load in xyz.tcl.

Here's a simple example. This is xyz.tcl:

set SomeVariable 12345

This is abc.tcl:

source xyz.tcl
puts "The password on my luggage is $SomeVariable"

The source command is really very simple internally. It just reads in the contents of the file (into a string), and then internally evals that string. Yes, this means that you probably shouldn't put source inside a procedure, at least not unless you're sure what the consequences of this are.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.