beetlebug▾
/

auto_execokexec

Gives the full path of the program that exec runs for a program word.

auto_execok NAME

Description

Gives a list with one element, the full host path of the program that exec runs for the word NAME, or an empty string when exec gives an error for NAME. The lookup is the lookup of exec: a word with a path separator must be a full path, and a bare name goes through the PATH of the environment of exec, or /usr/bin:/bin when it has none. The allowlist of the embedder (--exec-allow) applies, so a program that the list does not have gives an empty string. On Windows a bare name gets each extension of PATHEXT, or .COM and .EXE, and the system folder is the PATH when the environment has none. An empty NAME gives an empty string.

Each call does the lookup again, and no auto_execs array exists. With the capability package and no exec, auto_execok is the proc of the Tcl library, which looks in the folders of env(PATH) with file executable.

The setup of the examples picks /bin/sh, or cmd.exe on Windows, as shell.

Arguments

ArgumentTypeDefaultDescription
NAMEprogram wordrequiredThe first word of a program of exec: a bare name or a full path.

Returns

A list with one full path, or an empty string.

Examples

Each example of this page runs after # A shell of the host: /bin/sh, or cmd.exe on Windows. In host mode the separator of Windows is a backslash. set shell [expr {[file separator] eq "/" ? "/bin/sh" : "cmd.exe"}] .

% llength [auto_execok $shell]
1

% file exists [lindex [auto_execok $shell] 0]
1

% auto_execok nosuchprogram_zz

# A relative path is an error of exec, so the result is empty.
% auto_execok bin/prog

% auto_execok ""

Errors

% auto_execok
wrong # args: should be "auto_execok name"
-errorcode TCL WRONGARGS

% auto_execok a b
wrong # args: should be "auto_execok name"
-errorcode TCL WRONGARGS

Differences from Tcl

Facts

Capability
exec. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.2

See also