Porting To Windows

If you are porting Tcl code that was developed on a Unix/Linux box to Windows then read this page before you do the port, it will save you time and grief. Most of this stuff on this page is documented in the Tcl man pages but can be a surprise when you are doing a port. If you find issues not mentioned here please add them to this page.

tomk


VARIABLES

The "env" (array) variable

Under Windows, the environment variables PATH and COMSPEC in any capitalization are converted automatically to upper case. For instance, the PATH variable could be exported by the operating system as “path”, “Path”, “PaTh”, etc., causing otherwise simple Tcl code to have to support many special cases. All other environment variables inherited by Tcl are left unmodified. Setting an env array variable to blank is the same as unsetting it as this is the behavior of the underlying Windows OS. It should be noted that relying on an existing and empty environment variable will not work on Windows and is discouraged for cross-platform usage.

The "tcl_pkgPath" variable

This variable holds a list of directories indicating where packages are normally installed. It is not used on Windows.

The "tcl_rcFileName" variable

This variable is used during initialization to indicate the name of a user-specific startup file. If it is set by application-specific initialization, then the Tcl startup code will check for the existence of this file and source it if it exists. For example, for wish the variable is set to ~/.wishrc for Unix and ~/wishrc.tcl for Windows.

The "tcl_wordchars" variable

The value of this variable is a regular expression that can be set to control what are considered “word” characters, for instances like selecting a word by double-clicking in text in Tk. It is platform dependent. On Windows, it defaults to \S, meaning anything but a Unicode space character. Otherwise it defaults to \w, which is any Unicode word character (number, letter, or underscore).

The "tcl_nonwordchars" variable

The value of this variable is a regular expression that can be set to control what are considered “non-word” characters, for instances like selecting a word by double-clicking in text in Tk. It is platform dependent. On Windows, it defaults to \s, meaning any Unicode space character. Otherwise it defaults to \W, which is anything but a Unicode word character (number, letter, or underscore).

COMMANDS

The "file" command

There are many portability issues. Be sure to read the sections on "file link", "file nativename" and "file normalize".

The "exec" command

Read the sections on "PORTABILITY ISSUES" and "WINDOWS EXAMPLES"

The "glob" command

Read the section on "WINDOWS PORTABILITY ISSUES"

The "load" command

Read the section on "PORTABILITY ISSUES".

The "open" command

Read the sections on "PORTABILITY ISSUES" and "ERROR CODES (Windows only)".

WINDOWS SPECIFIC TCL COMMANDS

The "registry" command

NASTY STUFF THAT CAN BITE YOU IN THE ASS

The glob doesn't doesn't (i.e. can't be made to) return everything in a windows folder that has the "hide" flag set.

Even better, there's a "system" flag, which automatically forces "hidden". You can't un-hide a system file without un-system'ing it as well...