Version 15 of auto_execok

Updated 2005-11-10 10:44:48

auto_execok is one of several commands documented at http://www.tcl.tk/man/tcl8.4/TclCmd/library.htm


Canonical example usage:

    eval exec [auto_execok dir] *.$suffix

or, with 8.5 [L1 ],

    exec {expand}[auto_execok dir] *.$suffix

CL now regards this as canonical only in a rather arcane sense, because dir presents so many problems. Perhaps most immediate is that glob provides a stylistically superior alternative.

[Explain why this is better than $::env(COMSPEC), cmd.exe, ...]

LES on September 16, 2004: auto_execok is better than $::env(COMSPEC) and cmd.exe? Get outta here... :-)


To demonstrate why [eval] was required before 8.5:

 % auto_execok start
 C:/WINNT/system32/CMD.EXE /c start
 % exec [auto_execok start] http://wiki.tcl.tk
 couldn't execute "C:\WINNT\system32\CMD.EXE \c start": invalid argument
 % eval exec [auto_execok start] http://wiki.tcl.tk
 % # success

Note that if any arguments to "start" have spaces (or other white space, or other syntactically-privileged characters) in them, you have to list-protect them from eval

 % set mydoc "My document.doc"
 % eval exec [auto_execok start] $mydoc
 % # msword may complain about being unable to find "My" and "document.doc"'
 % eval exec [auto_execok start] \"\" [list $mydoc]; # should be more successful
 % # Dont't forget the '\"\"' otherwise "My document.doc" is used as the window-titel for
 % # a DOS-shell.

MHo Has someone noticed this:

 % auto_execok start
 C:/WINNT/system32/cmd.exe /c start
 % exec -- [auto_execok start] &
 couldn't execute "C:\WINNT\system32\cmd.exe \c start": no such file or directory
 %

It seems that exec together with auto_execok translates all forward-slashes in the command into backslashes!


See also exec, Invoking browsers,


Tcl syntax help - Arts and crafts of Tcl-Tk programming - Category Command