util::which (public)

 util::which prog

Defined in packages/acs-tcl/tcl/utilities-procs.tcl

Use environment variable PATH to search for the specified executable program. Replacement for UNIX command "which", avoiding exec. exec which: 3368.445 microseconds per iteration ::util::which: 282.372 microseconds per iteration In addition of being more than 10 time faster than the version via exec, this version is less platform dependent.

Parameters:
prog (required)
name of the program to be located on the search path
Returns:
fully qualified name including path, when specified program is found, or otherwise empty string
Author:
Gustaf Neumann

Partial Call Graph (max 5 caller/called nodes):
%3 test_acs_lang_exec_dependencies acs_lang_exec_dependencies (test acs-lang) util::which util::which test_acs_lang_exec_dependencies->util::which test_acs_subsite_exec_dependencies acs_subsite_exec_dependencies (test acs-subsite) test_acs_subsite_exec_dependencies->util::which test_acs_tcl_exec_optional_dependencies acs_tcl_exec_optional_dependencies (test acs-tcl) test_acs_tcl_exec_optional_dependencies->util::which test_acs_tcl_exec_required_dependencies acs_tcl_exec_required_dependencies (test acs-tcl) test_acs_tcl_exec_required_dependencies->util::which test_file_storage_exec_dependencies file_storage_exec_dependencies (test file-storage) test_file_storage_exec_dependencies->util::which ad_file ad_file (public) util::which->ad_file Object ::throttle Object ::throttle (public) Object ::throttle->util::which aa_test::write_test_file aa_test::write_test_file (private) aa_test::write_test_file->util::which acs_admin::check_expired_certificates acs_admin::check_expired_certificates (private) acs_admin::check_expired_certificates->util::which apm_gzip_cmd apm_gzip_cmd (public) apm_gzip_cmd->util::which apm_tar_cmd apm_tar_cmd (public) apm_tar_cmd->util::which

Testcases:
acs_lang_exec_dependencies, acs_subsite_exec_dependencies, acs_tcl_exec_required_dependencies, acs_tcl_exec_optional_dependencies, file_storage_exec_dependencies
Source code:
    set key ::acs::which($prog)

    if {[info exists $key]} {
        return [set $key]
    }
    if {$prog ne ""} {

        switch -- $::tcl_platform(platform) {
            windows {
                #
                # Notice: Windows has an alternative search environment
                #         via registry. Maybe it is necessary in the future
                #         to locate the program via registry (sketch below)
                #
                # package require registry
                # set key {HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths}
                # set entries [registry keys $key $prog.*]
                # if {[llength $entries]>0} {
                #   set fullkey "$key\\[lindex $entries 0]"
                #   return [registry get $fullkey ""]
                # }
                # return ""
                #
                set searchdirs [split $::env(PATH) \;]
                set exts       [list .exe .dll .com .bat]
            }
            default {
                set searchdirs [split $::env(PATH) :]
                set exts       [list ""]
            }
        }
        set names [lmap ext $exts {set _ $prog$ext}]
        if {[ad_file pathtype $prog] ne "relative"} {
            set fullNames $names
        } else {
            set fullNames {}
            foreach dir $searchdirs {
                foreach name $names {
                    lappend fullNames [ad_file join $dir $name]
                }
            }
        }
        foreach fullName $fullNames {
            if {[ad_file executable $fullName]} {
                return [set $key $fullName]
            }
        }
    }
    return ""
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-tcl/tcl/utilities-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: