ActiveState Community

Correctly using source and exec in TclApp

Posted by jeffg on 2006-09-05 12:10
OS: All / Any | Product: Tcl Dev Kit | tags: tclapp tcltk
Question:

When I wrap my Tcl application with TclApp, I get errors when my code tries to source or exec another wrapped tcl file.

Answer:

This is usually a problem with relative paths within TclApp's vfs. Here is an example for how to work around this:

package require Tk

set ::DIR [file dirname [info script]]

button .b -text 'Kill!' -command {source $::DIR/sourced.tcl }

pack .b

This script is setting $::DIR to be the basepath of the current
script. You can use this value to source or exec other scripts either when
wrapped or running as a script, regardless of what CWD is.