开发者

Run common TCL script on Windows and Linux

I am new to TCL. How ca开发者_StackOverflow社区n I run a common tcl script across Windows and Linux? I'd like to check platform type first and then call appropriate tcl proc.


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 ...
}


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!


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜