Execing Processes

Tycho includes a few different ways of running subprocesses.

::tycho::tyexec args
The tyexec procedure is a wrapper to the the Tcl exec command which checks to see if exec is supported on the current platform and gives a better error message if the exec returns non-zero. tyexec is non-graphical, and resides in the tycho.kernel.basic package.
::tycho::execModal args
The execModal procedure is a short cut to the ::tycho::Monitor class. execModal is graphical, and resides in the tycho.kernel.gui package along with the Monitor class.
::tycho::Monitor
The graphical Monitor Class brings up a dialog widget that allows the user to type in a command and view the output.

Platform Exec Policies

Consult the Tcl man pages for open and exec for descriptions of platform dependencies.

Code that calls exec on the Macintosh

Neither ::tycho::tyexec or the Exec class will work on the Macintosh, so all methods that call these two methods should check the $tcl_platform variable at the top of the method and call error with an informative error message.

body ::tycho::MyClass::myMethod {} {
	global tcl_platform
	if {$tcl_platform(platform) == "macintosh"} {
		error "Sorry, the myMethod method in MyClass is not\
			supported on the Macintosh as it\ncalls the\
			tcl \"exec\" command which is not available." 
	}

	# The rest of the method . . .
}

In addition, any menu choice that calls a method that eventually calls exec should be disabled on the Macintosh. In the example below, from $TYCHO/kernel/gui/Edit.itcl, we check the tcl_platform variable and disable the menu item if we are on the Mac.

body ::tycho::Edit::constructor {args} {
    global tcl_platform
    # . . .

        $myMenubar add "Spelling..." Edit -underline 2 \
                -accelerator "M-$" -command "$this spellCheck"
	if {$tcl_platform(platform) != unix} {
	    $myMenubar disable "Spelling..."
	}

Code that calls exec under Windows

The Tcl exec command works under Windows, but there are various limitations, see the Tcl exec man page.

Some of the classes in Tycho include execs of external commands that are not shipped with Tycho. The Tycho policy is to allow these commands to be exec'd under Windows, as the user may have installed third-party commands.

Common exec mistakes

  1. In Itcl2.1 and later, there is no need to do exec date. Instead, call clock format [clock seconds].
  2. Itcl2.2 is based on Tcl7.6, in which the Tcl file command has been extended with subcommands that copy, delete, and rename files. In addition, there is a file subcommand that will make a directory.
  3. Be sure to wrap exec chmod ... calls with catch so that the command does not fail on non-unix platforms. The details of file permissions on non-Unix are a little murky, but wrapping catch around the chmod call will probably make your code more robust.
  4. Call ::tycho::tyexec rather than just calling exec. If there is a problem, ::tycho::tyexec will bring up an error window that includes the command that failed to exec.

Tycho Home Page


Copyright © 1996-1998, The Regents of the University of California. All rights reserved.
Last updated: 06/08/98, comments to: cxh@eecs.berkeley.edu