"exec source – Amir Rachum Feb 22 '10 at 15:31

  • Hi Amir, exec is always going to call an OS executable file. If you need to execute as running from the c-shell or bash or ... you need to use the second option: exec [info nameofexecutable] – Carlos Tasada Feb 22 '10 at 15:41
  • I get "couldn't read file "source": no such file or directory" – Amir Rachum Feb 22 '10 at 15:49
  • Umm, Amir, what's the result of executing 'info nameofexecutable'? I'm doing this kind of things in my code in a lot of places and it works. Looks like we're having some kind of misunderstanding. – Carlos Tasada Feb 22 '10 at 15:55
  • The preceding error was when using 'info nameofexecutable'. I get "couldn't read file "source": no such file or directory". – Amir Rachum Feb 22 '10 at 15:56
  • 'info nameofexecutable' is supposed to return the name (and path) of your tclshell executable. "couldn't read file" is expected when the file you want to open (or source in this case) is not found. Please try to execute the next script and paste the result, replacing at the beginning by you real source file. ------------ set mysource "" puts "exe: [info nameofexecutable]" puts "Exists source? $mysource -> [file exists $mysource]" source "[info nameofexecutable]" "$mysource" ------------ – Carlos Tasada Feb 22 '10 at 16:11
  • this would run "source " with tclsh which is not what I want... Also, where do I put the arguments for the script? – Amir Rachum Feb 22 '10 at 16:26
  • 1

    Some confusion here. exec runs a separate program, possibly with arguments. source is not a separate program, it is another Tcl command which reads a file of Tcl commands and executes them, but does not pass arguments. If the other script you are trying to call is written to be run on from the command line, it will expect to find its arguments as a list in variable argv. You can fake this by setting argv to the list of arguments before running source, eg.

    set argv {first_arg second_arg}
    source script_path
    

    Alternatively you could use exec to start a whole separate Tcl executable and pass it the script and arguments:

    exec script_path first_arg second_arg
    
    Colin Macleod
    • 4,222
    • 18
    • 21
    • 1
      the second deos assume the script itself has the necessary exec magic at the top to make it executable, otherwise you may need to exec tclsh or wish with it as an argument – jk. Feb 22 '10 at 16:52
    • Absolutely right thanks, may need: exec tclsh script_path first_arg second_arg – Colin Macleod Feb 22 '10 at 16:56
    0

    Recently I wanted to set some UNIX environment variables by sourcing a shell script and stumbled across the same problem. I found this simple solution that works perfectly for me:

    Just use a little 3-line wrapper script that executes the source command in a UNIX shell before your Tcl script is started. Example:

    #!/bin/csh
    source SetMyEnvironment.csh
    tclsh MyScript.tcl
    
    0

    the error speaks for itself. Make sure you give the correct path name, specify full path if necessary. and make sure there is indeed the file exists in that directory

    ghostdog74
    • 327,991
    • 56
    • 259
    • 343