Write Once, Run Where?

Tcl is a multiplatform language, running on various Unix systems, Microsoft Windows NT/95/98, and Apple Macintosh. Tcl provides a great deal of machine and operating system independence. If writing portable software is your goal, there are a few areas that still need special attention.

Filenames and Pathnames

Filenames and pathnames differ among Unix, Windows, and Macintosh. Fortunately, Tcl is happy to work with Unix-style filenames internally. The file command provides help for dealing with filenames when you need to convert between the canonical form and forms required by specific operating systems. You will likely need a native filename if you exec programs that require filenames.

On Unix, the file command takes two or more file pathname components and joins them with the Tcl canonical path delimiter “/”:

file join /home tpoindex src tcl style.tcl

This code produces the following output:

/home/tpoindex/src/tcl/style.tcl

On Windows, the file command takes a pathname in canonical network form and returns the native pathname:

file nativename "/program files/tcl/bin/wish80.exe"

This code produces the following output:

\program files\tcl\bin\wish.exe

The file command has many other subcommands to delete, copy, and rename files in an operating system--independent fashion.

End of Line Conventions

Unix, Windows, and Macintosh each have different end of line conventions for text files. In the default state, Tcl is very forgiving in reading files created on a different platform. ...

Get Tcl/Tk in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.