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.
When you have installed Tcl, the program you will then call to utilize it is tclsh . For instance, if you write some code to a file "hello. tcl", and you want to execute it, you would do it like so: tclsh hello.
You can run this program by starting tclsh from the start menu, then typing the command source c:/hello. tcl.
The first way is to build both platforms in the unix subdirectory. First configure and build for one platform. After you install, type make distclean and then configure and build for the second platorm. Be sure that both the configure and build steps are run on the platform for which you are building.
A Tcl script can be invoked from inside another Tcl script (or from the command line) using the Tcl command "source". This will transfer control to the <tcl script> execute the commands there until they complete, and then return control bacl to the script (or command line) that executed the "source" command.
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:
file join
instead of concatenating with /
in between.file nativename
to make filenames to hand off to subprocesses.load
; what it does is not at all portable.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.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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With