Execing Processes

Tycho includes a few different ways of running subprocesses.

::tycho::invoke args
The invoke procedure will pass args to the Tcl exec command.
::tycho::Exec
The Exec 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::invoke 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/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 commmand 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.

    The tycho procs ::tycho::rm and ::tycho::mkdir can be uses with Itcl2.1 and Itcl2.2. These procs check the itcl version number and then act accordingly.

  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::invoke rather than just calling exec. If there is a problem, ::tycho::invoke will bring up an error window that includes the command that failed to exec.

Tycho Home Page


Copyright © 1996, The Regents of the University of California. All rights reserved.
Last updated: 12/16/96, comments to: cxh@eecs.berkeley.edu