From 7cc11e7898250b5551da49ce1e719fcd8311c664 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Tue, 28 Oct 2014 09:19:20 +1000 Subject: Fix [info nameofexecutable] after [cd] If argv0 is a relative path, [info nameofexecutable] returned the wrong result after changing directory. So calculate and stash the result during init. Also move internal $jim_argv0 into namespace jim as $jim::argv0 Signed-off-by: Steve Bennett --- stdlib.tcl | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'stdlib.tcl') diff --git a/stdlib.tcl b/stdlib.tcl index d0256d0..3a2bbd8 100644 --- a/stdlib.tcl +++ b/stdlib.tcl @@ -79,21 +79,12 @@ proc errorInfo {msg {stacktrace ""}} { string trim $result } -# Finds the current executable by searching along the path -# Returns the empty string if not found. +# Needs to be set up by the container app (e.g. jimsh) +# Returns the empty string if unknown proc {info nameofexecutable} {} { - if {[info exists ::jim_argv0]} { - if {[string match "*/*" $::jim_argv0]} { - return [file join [pwd] $::jim_argv0] - } - foreach path [split [env PATH ""] $::tcl_platform(pathSeparator)] { - set exec [file join [pwd] [string map {\\ /} $path] $::jim_argv0] - if {[file executable $exec]} { - return $exec - } - } + if {[exists ::jim::exe]} { + return $::jim::exe } - return "" } # Script-based implementation of 'dict with' -- cgit v1.1