12.4.31    SCREXEC

Description:   Execute an external script.  Downloads the file if it does not exist or if a newer version exists on SCADA node.  Performs the script commands found in the file   SCREXEC should be used instead of the  "source" command  in Tcl. Assumes script is of same type (e.g. Tcl can only call another Tcl, JScript can call only another JScript, VB Script can only call another VB Script).

Syntax:

Tcl:              SCREXEC filename

                  

 JScript:        SCREXEC("filename");

                  

 VB Script:     SCREXEC "filename"

                  

Argument:     file name, optionally path

Returns:        error or return defined in script

See Also:       catch, source, MCREXEC, SCRLOOP

 

SCREXEC will download the called script file if it does not exist, then execute the Script.

The script must of same type (e.g. Tcl can only call another Tcl, JScript can call only another JScript, VB Script can only call another VB Script).

SCREXEC replaces the source command in standard Tcl .  It is recommended to use the SCREXEC instead of source. The limitation of the source command is that it will not download the source file to the client.

This command takes the contents of the specified file or resource and passes it to the script 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 SCREXEXC action 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 SCREXEC action will return normally with the result from the return command. SCREXEC will return the value of any returns in the source script.

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

To see this error, you should use the catch (Tcl), On Error (VB Script), or try catch (JScript) commands.  Note that ACTION commands do not return errors other than syntax.

The SCREXEC action 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.  SCREXEC 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 called script contains declaration of global variables, that script 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.

In WebAccess, SCREXEC can be used in lieu of the package command found in other scripting implementations.  The method would be implemented using a start-up script and declaring global variables and procedures.

 

Examples:     

# Tcl example 1

SCREXEC sourcein.scr

 

# Tcl example 2 - relative path

SCREXEC ../bgr/sourcein.scr

 

# Tcl example 3 - absolute path

SCREXEC c:/webacccess/LiveDEMO_SCADAnode1/bgr/sourcein.scr

 

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

# occurs- Failed. couldn't read file "sourcein.scr": no such file 

# or directory (assuming text and text50 are tags on a display)

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

   SETVAL "text=Failed. $err "

   SETVAL text50=[string range $err 61 112]

   }

 

Rem DebugVBScript.vbs - a VB Script

Rem to print errors of other VB scripts.

Dim fso, filespec, msg

 Set fso = CreateObject("Scripting.FileSystemObject")

 filespec = GETVAL("TestScriptName")

On Error Resume Next

SCREXEC filespec

WINEXEC "BWSPOOL.EXE"

   If (fso.FileExists(filespec)) Then

      msg = filespec & " exists."

      BWSPOOL msg

      BWSPOOL VbCrLf

      If Err.Number <> 0 Then

        rem print error number and description

        BWSPOOL "Error # " & CStr(Err.Number) & " " & Err.Description

        SETVAL "ERROR=" & CStr(Err.Number) & " " & Err.Description

        rem print carriage return and line feed

        BWSPOOL VbCrLf

      Else

        BWSPOOL "No reported errors "

        BWSPOOL filespec

        BWSPOOL VbCrLf

      End If

 

// DebugJScript.js - a JScript

// open the spooler window to print the file

WINEXEC("BWSPOOL.EXE");

BWSPOOL("\r\n");  //print a carriage return and line feed

var e, fso, f, s, filespec, ForReading;

ForReading = 1, s = "", e = "No reported errors.";

// get the name of the file to run from a text tag

   filespec = GETVAL("TestScriptname");

// Run the script and catch any errors.

try {

     SCREXEC(filespec);

     BWSPOOL("Try to run ");

     BWSPOOL(filespec);

     BWSPOOL("\r\n");

     // Test if it exists

      s = filespec;

      fso = new ActiveXObject("Scripting.FileSystemObject");

      if (fso.FileExists(filespec)) {

        s += " found.";

      }

      else

      {

         s += " file not found.";

         e = " file not found.";

      }   

     BWSPOOL(s);

     BWSPOOL("\r\n");

} catch (e) {

     // print any errors

     BWSPOOL(e);

} finally {

}

if (e == "No reported errors.")

 BWSPOOL(e);

 

# DebugTclScript.scr - a Tcl script

# Open Message spooler window

WINEXEC BWSPOOL.EXE

# Exit if it calls itself, it will loop endlessly

# trim blank characters

set scriptname [string trim [GETVAL TestScriptname]]

BWSPOOL "Requested script is "

BWSPOOL $scriptname

BWSPOOL "\r\n" #print Carriage return and line feed

if {$scriptname == "DebugTclScript.scr"} then {

 BWSPOOL "don't call itself. Will create an endless loop."

 return

}

# Run the script put errors in err

catch "SCREXEC [GETVAL TestScriptname]" err

  

if {[file exists [GETVAL TestScriptname]]} then {

   #figure out if blank - No errors

   set msglength [string length $err]

   if {$msglength <= 0} then {

   set err "No reported errors."

   }

   BWSPOOL $err

 } else {

 BWSPOOL "[GETVAL TestScriptname] ... File not found."

 }

BWSPOOL "\r\n"

SETVAL ERROR=$err

SETVAL ERRORL2=[string range $err 71 140]