12.5.36    source

Description:   call an external script file and execute it.

                   Replaced by SCREXEC ACTION command

Syntax:         source filename

                   source path/filename?

         

Argument:     file name, path

Returns:        error or return defined in script

See Also:       SCREXEC, proc, global, namespace, variable

 

Examples:     

#example 1

source sourcein.scr

 

#example 2 - relative path

source ../bgr/sourcein.scr

 

#example 3 - absolute path

source c:/webaccess/projectnode/bgr/test1.scr

 

#example 4 - runs script source.scr - traps and displays if error

# Failed. couldn't read file "bgt/sourcein.scr": no such file or

#  directory

if {[catch [list source sourcein.scr] err]} {

   SETVAL "text=Failed. $err "

   SETVAL text50=[string range $err 61 112]

   }

 

This command does not work on the browser-based client.  It is recommended to use the SCREXEC instead.

The limitation of source is that it will not download the source file to the client.  Consequently, it does not work on the client  unless the source file is manually copied to the client in some way. It works well on the local SCADA node.

This command takes the contents of the specified file or resource and passes it to the Tcl interpreter as a text script. The return value from source is the return value of the last command executed in the script. If an error occurs in evaluating the contents of the script then the source command will return that error. If a return command is invoked from within the script then the remainder of the file will be skipped and the source command will return normally with the result from the return command.

The source command can be used like the include command in c programs.  It is most commonly used to call an external script. The external script can be a set of procedures.  The source is most commonly used for large complex procedures or subroutines that do not need to be modified, but are called in a simple smaller script.   If the source script contains declaration of global variables, that source needs to run only once each time the script environment starts ( for example as long as the window is running for a screen script or the system is running for a global script).  See global for more description.

The most common error is :
couldn't read file "filename": no such file or directory .

Source will return the value of any returns in the source script.

In WebAccess, SCREXEC can be used in lieu of package, package require commands in other Tcl implementations by implementing a start-up script and declaring global variables and procedures.