Getting the proc path in TCL, which is called from another script

I am new to TCL programming

I have a tcl script called test1.tcl and test2.tcl separately in two different

of the directories F: \ TCLPrograms \ SamplePrograms \ test1.tcl and F: \ TCLPrograms \ test2.tcl

I want to know the full path of test2.tcl, which is proc

if I provide [script] information inside proc disp {}, it returns the path from which it is called

ie F: \ TCLPrograms \ SamplePrograms \ test1.tcl

kindly someone will tell me to get the path to proc

test1.tcl:

puts "Processing test1..."
source "F:\\TCLPrograms\\test2.tcl"
set rc [disp]
puts "Executed...."

test2.tcl:

proc disp { } {
puts "Successfully executed test2.tcl"
set path [info script]
puts "Script is invoked from the path: $path"
}

Thanks in advance

+3
source share
1 answer

info script source, . (, 8.6 8.5 ActiveState, .)

- , :

variable dispScriptFile [file normalize [info script]]
proc disp {} {
    variable dispScriptFile
    puts "Successfully executed test2.tcl"
    set path [file dirname $dispScriptFile]
    puts "Script is invoked from the path: $path"
}

, , , , cd . ( test2.tcl , .)

+6

Source: https://habr.com/ru/post/1796273/


All Articles