Printer FriendlyEmail Article Link

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

Objective/Summary
  • In order to execute a python script from the command sequencer it will be necesary to either use:
    • The "Global Services: Run Custom Command" sequencer command and a TCL script that executes the Python script from it.
    • Or the "Run External Process Command"
  • In both cases the Python script is not capable of executing any Spirent TestCenter API specific commands that belong to the GUI session it is being executed from. It would be a standalone script.
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()
  • Another option is to use the "Run External Process Command"
    • This basically runs a command from your Windows Command prompt.
      It could be like a simple c:\dir command or it could be a script. 
      Whatever is done on this external process is outside of TestCenter config itself.
      In this case you "can" run a python script but as mentioned, it is external to TestCenter.
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

 

Product : Spirent TestCenter