Spirent TestCenter: How do you execute a python script using the "Global Services: Run Custom Command" sequencer command?


Doc ID    SOL14356
Version:    4.0
Status:    Published
Published date:    07/29/2020
Created Date:    07/23/2020
 

Objective/Summary

In order to execute a python script from the command sequencer it will be necesary to use the "Global Services: Run Custom Command" sequencer command and a TCL script that executes the Python script from it.

Environment/Versions

STC
Command sequencer
"Global Services: Run Custom Command" sequencer command
Python and TCL already installed and configured in the environment variable PATH

Procedure

In the command sequencer add the "Global Services: Run Custom Command" command and set the filepath of the TCL script.
In the TCL script use the "exec" function to call the Python script, refer to the example below:

This example will create a text file from the TCL script and another file from a Python script called from the TCL script
The file that should be set in the "Global Services: Run Custom Command" command must be the TCL script

TCL script "tcl_script.tcl"

puts "exec python"
exec python "C:/the/full/filepath/python_script.py"

puts "create tcl file"
set fp [open "C:/the/full/filepath/file_tcl.txt" w+]
puts $fp "Test from tcl"
close $fp

puts "tcl script finished"

return 1


Python script "python_script.py"
f = open("C:/the/full/filepath/file_python.txt", "w")
f.write("Test from python")
f.close()

 

Notes

The Python interpreter used is 2.7.14

You must configure the “Tcl/Tk Installation Path” in the GUI (going to Tools-->Options->Tcl/Tk ), you should select the path up to the “TCL” directory:
i.e.:
C:\Program Files\Spirent Communications\Spirent TestCenter 4.90\TCL

Find Answers

Specified Languages
English
中文

Please Sign In

Username
Password

Did you forget your password?
Click here for assistance

New user? Start here.