Remember that the
source command instructs the Tcl interpreter to read and execute the file you name
as part of the same process that's currently executing. It does
not start another program running in parallel with the one currently executing.
The only reasons I can think of for
source not being able to read the file are:
[ul][li]Your script executed a
cd command at some point to change its current working directory. You can test this by having your script print the return value of the Tcl
pwd command. If this is the problem, either change back to your original directory, or use an absolute or relative pathname when you
source the script.[/li]
[li]You have some sort of file permissions problem. Check to make sure that you have read permission on the files you're sourcing.[/li]
[li]You misspelled the name of the file you're sourcing.[/li][/ul]
I'm particularly concerned about the crashed X server. In general, Tcl shouldn't do things like that. And it's very difficult to diagnose a problem like that without a lot more information about your scripts. There's one potential cause I can think of. (And it relates to the idea that you might really be wanting to
exec your script instead of sourcing it. More about that below.) If you use both the
grid command and the
pack command to manage widgets within a single parent (either a frame or a toplevel window), the contention between the geometry managers has been known to crash older X servers. Your guidelines for using
pack and
grid is to use only one geometry manager within a single manager widget. You can use a different geometry manager within a descendant widget (for example, you can
grid the contents of a frame, and then
pack the frame into a toplevel), but you can't mix both at the same level.
But getting back to the idea that
source might not be the command you really want. If you want to have your script execute another program in parallel with a script already executing, you want to use the Tcl
exec command. Give the
exec the name of the program to execute (providing an absolute path, if the program isn't in one of the directories listed in your system's
PATH environment variable) along with any arguments you want to pass to the program.
Keep in mind that if you want your script to start another Tcl script, you actually want to execute the
tclsh (or
wish) interpreter, passing the name of the script as a command-line argument. Thus, for
test1.tcl to execute
test2.tcl, the command to use in
test1.tcl would be:
Note that the
exec command doesn't return until the program executed terminates. The return value of
exec is any output generated by the program.
If the program you execute takes a long time to run (or runs until explicitly killed), you might want to tell
exec to start the program running in the background, and to then return immediately. To do so, use "&" as the last argument to
exec. For example:
[tt]exec tclsh test2.tcl
&[/tt]
The downside to this technique is that any output produced by the program is discarded. You can instruct
exec to redirect the output to a file, for example:
[tt]exec tclsh test2.tcl
>output.txt &[/tt]
But overall, this is a simplistic technique. Tcl has more elegant interprocess communication mechanisms, but that would require a much longer reply to describe.
- Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax