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. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access