Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run common TCL script on Windows and Linux

Tags:

tcl

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.

like image 555
Nimesh Kumar Avatar asked Jul 16 '10 02:07

Nimesh Kumar


People also ask

How do I run a Tcl script in Windows?

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.

How do I run a Tcl script in Linux?

You can run this program by starting tclsh from the start menu, then typing the command source c:/hello. tcl.

How do I compile and run a Tcl script in Linux?

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.

How do you call a Tcl script from another Tcl script?

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.


3 Answers

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 ...
}
like image 138
Nimesh Kumar Avatar answered Oct 14 '22 06:10

Nimesh Kumar


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!

like image 23
Jackson Avatar answered Oct 14 '22 08:10

Jackson


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

like image 3
Donal Fellows Avatar answered Oct 14 '22 07:10

Donal Fellows