tags:

views:

108

answers:

3

I am new to TCL. How can I run a common tcl script across Windows and Linux? I'd like to check platform type first and then call appropriate tcl proc. Thank Nimesh

+3  A: 

You can start by looking at the tcl_platform array. On my (windows) machine this reports the following:

% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(machine)   = intel
tcl_platform(os)        = Windows NT
tcl_platform(osVersion) = 5.1
tcl_platform(platform)  = windows
tcl_platform(threaded)  = 1
tcl_platform(tip,268)   = 1
tcl_platform(tip,280)   = 1
tcl_platform(user)      = username
tcl_platform(wordSize)  = 4

On a Unix system the os and osVersion will be the values reported by uname -s and uname -r respectivley. If you need something more sophisticated then the platform package may be the way to go!

Jackson
A: 

Yup that worked, Jackson. Basically, I wanted to know what OS my script is running on, for example,

set OS [lindex $tcl_platform(os) 0]
if { $OS == "Windows" } {
    perform this ...
} else {
    perform that ...
}
Nimesh Kumar
It's usually enough to just check `$tcl_platform(platform)` as most recent versions of Windows are similar enough to each other and most Unixes are close enough.
Donal Fellows
+1  A: 

Most things in Tcl work the same on Windows and Unix; the vast majority of details where there differences are hidden. To handle the rest:

  • Use file join instead of concatenating with / in between.
  • Use file nativename to make filenames to hand off to subprocesses.
  • Be careful with load; what it does is not at all portable.
  • The info command has some useful things, such as the name of the Tcl interpreter (info nameofexecutable) so you can start up interpreters in subprocesses portably and easily.
  • Some things just aren't portable (e.g., access to the Windows registry).

There are some subtle differences too, but you'll have to guide us with what you're doing with your program so that we can know what bits matter (e.g., Windows locks executables when they're running while Unix doesn't; sometimes that changes things).

Donal Fellows