Tycho includes a few different ways of running subprocesses.
::tycho::tyexec
args
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
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
Consult the Tcl man pages for open
and exec
for descriptions of platform dependencies.
exec
on the MacintoshNeither ::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..." }
exec
under Windowsexec
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.
exec date
.
Instead, call clock format [clock seconds]
.
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.
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.
::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.