• Home
  • Company
    • About
    • Customers
    • Testimonials
    • Contact Us
    • My Account
  • Products
  • Downloads
  • Tutorials
  • Professional Services
  • Home
  • Company
    • About
    • Customers
    • Testimonials
    • Contact Us
    • My Account
  • Products
  • Downloads
  • Tutorials
  • Professional Services
Free Edition Compatible
How to Inter-Work with Tcl from ESL Script
Objectives
In this tutorial you'll learn HOW TO:
► Incorporate and call Tcl scripts from your ESL test 
► Mix ESL and inline Tcl commands in the same ESL script
► Load and inter-work with the pure Tcl script lacated in an external file 
► Inject input parameters to Tcl 
► Receive result values returned by your Tcl routines
All Tutorials
How to ...
Write a Script
Copy the script below to your ESL and run to explore how to inter-work with Tcl.
The script performs the following:
► Create Tcl object which is mandatory step.
► Define an inline Tcl routine to call it further on.
► Use TCL_Eval command to perform Tcl commands inline with ESL script.
► Receive results from Tcl script using output parameter Status containing the Tcl return value
► Open Windows file explorer using the ESL command InputOpenFileName to load your Tcl script file.
► Run your loaded Tcl with TCL_EvalFile ESL command.
► Make sure that your script releases all Tcl resources at the end, and deletes Tcl object with ESL TCL_Delete command.
 
     Declare  Status ,  TCL
    
     ; Create Tcl Interpreter object
     TCL_Create  TCL ,   "C:\Tcl\bin\tcl85.dll" ,   1
    
     ; Define a new inline Tcl funtion MyReturn2 
     TCL_AddCode  TCL
        proc MyReturn2  {arg1}   {
             if   { $arg1 < 100 }   {
                 return   "a"
             }   else   {
                 return   "b"
             }
         }
     TCL_EndCode
    
     TCL_Eval  Status ,  TCL ,   "set a 12"   ; Status contains 12 (equivalent to Status=12)
     TCL_Eval  Status ,  TCL ,   "set a 12^Jset b 16"   ; Status is 16
     TCL_Eval  Status ,  TCL ,   "set a 12^Jputs $a"    ; STatus  is 12
     ; Ccll MyReturn2 with parameter 21, Status will return 12
     TCL_Eval  Status ,  TCL ,   `puts " MyReturn2 of 21 is: [MyReturn2 21]"`   
     ; Ccll MyReturn2 with parameter 221, Status will return 16
     TCL_Eval  Status ,  TCL ,   `puts " MyReturn2 of 221 is: [MyReturn2 221]"`
     ; Ccll MyReturn2 with parameter 300, Status will return 16
     TCL_Eval  Status ,  TCL ,   `MyReturn2 300`
    
     ; Open Windows file explorer to load your Tcl script from a file. 
     Declare  FileName
     InputOpenFileName  Status ,  FileName 
     if  Status  !=   0   Then  
         ; Execute the loaded Tcl script as is.
         TCL_EvalFile  Status ,  TCL ,  FileName 
         TMMessage   GT_InfoID ,   'Result = '   $  Status 
     EndIf
    
     ; You must delete the TCL object at the end.
     TCL_Delete  TCL
    
;   Let _RetStat = 0
;   Let _RetVal  = 0
     End   ;@DBG:NEST - 1 - @DBG:IsInJob; Exit Current Test
Use ESL command ChDir to change the Windows current path.
This is required when your TCL opens some file (like SVC, etc.) without referring the full path.
For example:

ChDir  Status ,   "c:\myTcl\MyProject"
TCL_EvalFile  Status ,  TCL ,   "C:\myTcl\MyProject\MyTcl.tcl "
Download Your Free Edition
Resources
To do your hands-on practice more effective:
Watch the "How to Automate Windows Command Line Operations" tutorial.
Watch the "How to Write Data Driven Test" tutorial.
Install the ETS Free Edition on your PC.
Download the "Get Started" project with all up-to-date tutorial scripts. Unzip it to C:\ETS_Workspaces.
  • Home
  • Products
  • Downloads
  • Tutorials
  • Contact Us
  • Terms of Use
  • Privacy Policy

Copyright © 2002-2017 Coronys Ltd. All Rights Reserved.
 
Back to top