2

I have a tcl script drakon_gen.tcl . I am running it, from another script run.tcl like this:

source "d:\\del 3\\drakon_editor1.22\\drakon_gen.tcl"

When I run run.tcl I have following output:

This utility generates code from a .drn file.
Usage: tclsh8.5 drakon_gen.tcl <options>
Options:
-in <filename>          The input filename.
-out <dir>              The output directory. Optional.

Now I need to add to run.tcl options that are in the output. I tried many ways but I receive errors. What is the right way to add options?

1 Answer 1

4

When you source a script into a tcl interpreter, you are evaluating the script file in the context of the current interpreter. If it was written to be a standalone program you may run into problems with conflicting variables and procedures in the global namespace. One way to avoid that is to investigate the use of slave interpreters (see the interp command) to provide a separate environment for the child script.

In your specific example it looks like you just need to provide some command line arguments. These are normally provided by the argv variable which holds a list of all the command line arguments. If you define this list before sourcing the script you can feed it the required command line. eg:

set original_argv $argv
set argv [list "--optionname" "value"]
source $additional_script_filename
set argv $original_argv
Sign up to request clarification or add additional context in comments.

1 Comment

You might also need to set up the argc and argv0 global variables, though they're much more rarely used.

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.