Nagesh HS
Nagesh HS

Reputation: 95

How to run tcl script from another tcl script without sourcing it in main script?

I am trying to run test.tcl file from main.tcl file , without sourcing it and I am getting error saying no file or directory even though both script in same directory.

  main.tcl script content: 
  tclsh test.tcl
  exec "C:\\Tcl\bin|\test.tcl"
  tclsh test.tcl

  test.tcl script content: 
  puts "Executed Second script" 

I tried both exec command and tclsh commands and its not working. Could you please suggest some idea to handle it.

Upvotes: 0

Views: 1604

Answers (1)

Ron Norris
Ron Norris

Reputation: 2690

Leave test.tcl the same as it is. Change main.tcl as follows. It assumes that test.tcl and main.tcl are in the same folder. If you do use full or relative paths, note that when using \folder\subdir, you need to double-slash \\folder\\subdir, or just use single forward-slash (Tcl has *nix origins) /folder/subdir.

puts "From main.tcl launching test.tcl"
set result  [exec [info nameofexecutable] test.tcl]
puts $result

From the command line type:

tclsh.exe main.tcl

And the result will look like this:

From main.tcl launching test.tcl
Executed Second script

Upvotes: 2

Related Questions