Calling Scripting Languages from NI TestStand

Updated Feb 18, 2026

Environment

Software

  • TestStand
  • LabVIEW
  • LabWindows/CVI

Programming Language

  • Python

Re‑using existing code during a migration to a new test software framework can significantly reduce development time and cost. NI TestStand and NI LabVIEW both provide robust capabilities for integrating and executing code written in a wide range of programming languages, including Python.

 

This document outlines the different methods available for calling Python scripts from TestStand. It also walks through how to use the Call Executable step type to run scripts written in Python, Perl, or Tcl. This content is Part 2 of a three‑part series focused on leveraging scripting languages within TestStand, specifically designed with engineers and scientists in mind.

Table of Contents

    Python Adapter

    The Python Adapter enables seamless integration of Python scripts into both new and existing TestStand test systems. Designed with the same principles as other TestStand adapters, it provides a familiar workflow for developers while offering powerful capabilities for Python-based automation.

     

    The adapter supports all standard TestStand step types, including Action, String Value Test, Pass/Fail Test, Numeric Limit Test, and Multi‑Numeric Limit Test, allowing Python code to be integrated into sequences just like any other code module. Interpreter configuration is managed directly within the TestStand Sequence Editor, ensuring a smooth and intuitive experience when executing Python scripts.

     

    Supported Features

    The Python Adapter provides a wide range of capabilities, including the ability to:

    • Execute Python scripts (.py) on disk by:
      • Calling a function defined in a module.
      • Getting/Setting the attributes defined in a module.
      • Creating a class instance.
      • Calling a member function or static function defined in the class.
      • Getting/Setting member attributes or static attributes defined in the class.
    • Execute Python scripts in Python versions 2.7 or 3.6+ (for later editions, ensure to use the most recent version of TestStand for full functionality).
    • Execute Python scripts out-of-process in the CPython interpreter.
    • Convert data between Python and TestStand variables.
    • Store/reuse the Python object in a TestStand variable (Object Reference).

     

    You can also use multiple Python interpreter sessions to perform the following tasks:

    • Execute Python scripts in parallel.
    • Use multiple Python versions, such as 2.7 and 3.6, simultaneously in TestStand.

     

    For complete documentation on using the Python Adapter, including configuration, best practices, and advanced examples, refer to the TestStand Help: Python Adapter section.

     

    If you need to work with other scripting languages or interact with Python through the command line, the Call Executable step type remains a flexible alternative.

    [Back to TOC]

    Call Executable Step

    TestStand can call scripts written in languages such as Perl, Python, and Tcl using the Call Executable step type. TestStand can pass data into scripts, retrieve output, and access script‑generated error information

    • Passing Data to Scripts: Developers can pass data from TestStand to their scripts through command‑line arguments or through the Standard Input (stdin) stream. Using stdin allows developers to reuse scripts that normally expect interactive user input, enabling them to run automatically within TestStand.
    • Accessing Output in TestStand: After the script finishes execution, anything written to Standard Output (stdout) can be read by the TestStand sequence. This allows developers to determine the step status based on the script’s output.
    • Accessing Script Errors in TestStand: If an error occurs during script execution, the error information is available through Standard Error (stderr). This enables developers to detect and handle script errors appropriately.

     

    By taking advantage of TestStand’s access to an executable’s stdin, stdout, and stderr streams, developers can fully leverage the capabilities of their scripts within a TestStand environment. 

    [Back to TOC]

    Calling a Simple Script from TestStand Using Call Executable Step

    If you are new to scripting or do not have an interpreter installed, refer to Part 1: Introduction to Scripting in Perl, Python and Tcl. If you want to call scripts from LabVIEW instead of NI TestStand, use the System Exec VI. For a tutorial, see Call Perl and Python Scripts from LabVIEW.

     

    To call a script from TestStand, you will need:

    • A script to call (examples are provided in Perl, Python, and Tcl in the Attachments section)
    • An interpreter for your chosen scripting language
    • The NI TestStand Sequence Editor (or an Operator Interface that allows sequence modification)

     

    The scripts in this example simply prints "Hello World!" to the standard output stream.

    Perl: HelloWorld.pl
    #!/usr/bin/perl -w use strict; print "Hello World!\n";
    Python: HelloWorld.py
    #!/usr/bin/env python print "Hello World!"
    Tcl: HelloWorld.tcl
    #!/bin/sh # -*- tcl -*- # The next line is executed by /bin/sh, but not tcl \ exec tclsh "$0" ${1+"$@"} puts "Hello World!";

    Calling a script from TestStand is very similar to executing it from the Windows command line. If your script file extension is associated with the correct interpreter, you only need to use the Call Executable step and specify the script path. If the extension is not associated, specify the interpreter as the executable and pass the script filename as a command‑line argument.

     

    1. Open the NI TestStand Sequence Editor and create a new sequence file.
    2. Add a Call Executable step and rename it Call HelloWorld Script.
    3. In the Step Settings pane, open the Call Settings tab.
    4. Specify the script to execute:
      • Perl: HelloWorld.pl
      • Python: HelloWorld.py
      • Tcl: HelloWorld.tcl

     

    1. Save the sequence file as CallingHelloWorld.seq in the same folder as your script.
    2. Run the sequence file.

     

    Your execution report should indicate that the test passed and show an ExitCode of 0, meaning the script executed successfully.

     

    Note: If the script file is not associated with an interpreter, call the interpreter directly and include the script filename as a parameter. See the following screenshot for an example:

     

     

    Accessing Script Outputs from TestStand: Standard Output

    Most programming languages provide a standard output stream (stdout). TestStand allows you to capture this output using the Call Executable step. In this example, you will modify the HelloWorld sequence so the script output appears in the TestStand report.

     

    1. Open CallingHelloWorld.seq.
    2. Select the Call HelloWorld Script step.
    3. In the Step Settings pane, open the Standard Output/Error tab.
    4. Under Output Destination, choose Store in Variable/Property.
      • Leave the default value: Step.StdOutput.Text.

       

      1. In the Properties tab, select Additional Results.
      2. Click Add Result from List and select Standard Output.
        • This adds the stdout text to the report.

      1. Save the sequence file as CallingHelloWorldWithStdOut.seq.
      2. Run your sequence. Your report should now include the script’s standard output text.

       

      [Back to TOC]

      Passing Data to Scripts from TestStand: Command Line

      Most programming languages allow you to pass data to them when launching scripts through command‑line arguments—extra parameters typed after the script name. TestStand’s Call Executable step supports this functionality and enables you to pass parameters to external scripts in the same way.

       

      The following example scripts accept a series of numbers as command‑line arguments and write their summed result to the standard output stream.

      Perl: AddNumbersCommandLine.pl
      #!/usr/bin/perl –w
      use strict;
      
      #Command Line Arguements are stored in list @ARGV
      my $numArgs = $#ARGV + 1;
      my $sum = 0;
      
      #Iterate through each element and add to the sum
      foreach my $currentNumber (@ARGV)
      {
          $sum += $currentNumber;
      }
      
      print "Sum: ", $sum, "\n";
      Python: AddNumbersCommandLine.py
      #!/usr/bin/env python
      import sys
      
      #Command Line Arguements are stored in list argv
      numArgs = len(sys.argv) - 1
      
      sum = 0
      
      #Iterate through each element and add to the sum
      for n in range (1, len(sys.argv)):
          sum = sum + int(sys.argv[n])
      
      print "Sum:", sum, "\n"
      Tcl: AddNumbersCommandLine.tcl
      #!/bin/sh
      # -*- tcl -*-
      # The next line is executed by /bin/sh, but not tcl \
      exec tclsh "$0" ${1+"$@"}
      
      #Command Line Arguements are stored in list argv
      set numArgs $argc
      set sum 0
      
      #Iterate through each element and add to the sum
      foreach currentNumber $argv {
          set sum [expr $sum + $currentNumber]
      }
      
      puts "Sum: $sum\n"

      To pass command‑line arguments from TestStand to a script, simply enter the desired parameters into the Argument Expression field of a Call Executable step.

       

      1. Create a new sequence file.
      2. Add a Call Executable step and name it “Call AddNumbersCommandLine Script.”
      3. In the Step Settings pane, open the Call Settings tab.
      4. Set File Pathname to the appropriate AddNumbersCommandLine script.
      5. In Argument Expression, enter a series of numbers enclosed in double quotes. Example: "2 5 8"

       

       

      1. Switch to the Standard Output tab and store the output in: Step.StdOutput.Text
      2. In the Properties tab, select Additional Results.
      3. Click Add Result from List and select Arguments to include command‑line arguments in the report.
      4. Click Add Result from List again and select Standard Output to include the stdout stream in the report.
      5. Save the sequence file as PassingDataToScriptsCommandLine.seq in the same folder as the scripts.
      6. Run the sequence file. The report will display the arguments and the calculated sum.

       

      [Back to TOC]

      Passing Data to Scripts from TestStand: Standard Input

      Most programming languages provide a standard input stream (stdin) that programs can read from during execution. Although stdin typically defaults to the keyboard, NI TestStand allows you to pass data directly into this stream from a sequence. This gives developers greater flexibility because scripts can read values at run time rather than only when they start.

       

      Below are example scripts in Perl, Python, and Tcl that read a comma‑separated list of numbers from standard input, calculate their sum, and print the result.

      Perl: AddNumbersStdIn.pl
      #!/usr/bin/perl -w
      use strict;
      
      print "Enter numbers (separate with commas): ";
      
      #Get input as a string
      my $numbersAsString = <STDIN>;
      #Parse the numbers into a list
      my @numbers = split(/, | |,/,$numbersAsString);
      
      my $sum = 0;
      
      #Iterate through the list and add to the sum
      foreach my $currentNumber (@numbers)
      {
          $sum += $currentNumber;
      }
      
      print "Sum: ", $sum, "\n";
      Python: AddNumbersStdIn.py
      #!/usr/bin/env python
      
      #Get input as a list
      numbers = raw_input('Enter numbers (separate with commas): ')
      
      sum = 0
      
      #Iterate through the list and add to the sum
      for currentNumber in numbers:
          sum = sum + currentNumber
      
      print "Sum:", sum, "\n"
      Tcl: AddNumbersStdIn.tcl
      #!/bin/sh
      # -*- tcl -*-
      # The next line is executed by /bin/sh, but not tcl \
      exec tclsh "$0" ${1+"$@"}
      
      puts "Enter numbers (separate with commas): "
      #Get input as a string
      gets stdin numbersAsString
      #Parse the numbers into a list
      set numbers [split $numbersAsString ,]
      
      set sum 0
      
      #Iterate through the list and add to the sum
      foreach currentNumber $numbers {
          set sum [expr $sum + $currentNumber]
      }
      
      puts "Sum: $sum\n"

      To pass data through stdin from TestStand, you simply need to enable an Input Method on the Standard Input tab of the Call Executable step.

       

      1. Create a new sequence file.
      2. Add a Call Executable step and name it “Call AddNumbersStdIn Script.”
      3. In the Step Settings pane, open the Call Settings tab.
      4. Set the File Pathname to the appropriate AddNumbersStdIn script.
      5. Navigate to the Standard Input tab.
      6. Set Input Method to String and enter a comma‑separated list of numbers. Example: 2, 5, 8

       

      1. Go to the Standard Output tab and store the output in: Step.StdOutput.Text
      2. Open the Properties tab and select Additional Results.
      3. Click Add Result from List and enable:
        • Standard Input (to include stdin in the report)
        • Standard Output (to include stdout in the report)
      4. Save the sequence file as PassingDataToScriptsStdIn.seq in the same folder as the script.
      5. Run the sequence file. The generated report should resemble the example shown in the screenshot.

       

      [Back to TOC]

      Evaluating Script Results: Pass/Fail Test using Status Expression

      Earlier sections discussed how to capture the output of a script in TestStand using the Standard Output stream. Once this data is available in your sequence, TestStand allows you to determine the overall result of a step based on that output. One common method is to modify the Status Expression of a Call Executable step.

       

      This example script receives a minimum and maximum range through the standard input stream. It then compares a simulated voltage (hardcoded to 5 V) to the provided range and prints either “Result: True” or “Result: False” to standard output.

      Perl: IsVoltageInRange.pl
      #!/usr/bin/perl -w
      use strict;
      
      #Simulated Voltage
      my $voltage = 5;
      
      #Get Range
      print "Enter range (separate with commas): ";
      my $numbersAsString = <STDIN>;
      my @numbers = split(/, | |,/,$numbersAsString);
      
      my $min = $numbers[0];
      my $max = $numbers[1];
      
      if ($voltage >= $min && $voltage <= $max)
      {
          print "Result: True\n"
      }
      else
      {
          print "Result: False\n"
      }
      Python: IsVoltageInRange.py
      #!/usr/bin/env python
      
      #Simulated Voltage
      voltage = 5
      
      #Get Range
      numbers = input('Enter range (separate with commas): ')
      
      min = numbers[0]
      max = numbers[1]
      
      if voltage > min and voltage <= max:
          print "Result: True\n"
      else:
          print "Result: False\n"
      Tcl: IsVoltageInRange.tcl
      #!/bin/sh
      # -*- tcl -*-
      # The next line is executed by /bin/sh, but not tcl \
      exec tclsh "$0" ${1+"$@"}
      
      #Simulated Voltage
      set voltage 5
      
      #Get Range
      puts "Enter range (separate with commas): "
      gets stdin numbersAsString
      set numbers [split $numbersAsString ,]
      
      set min [lindex $numbers 0]
      set max [lindex $numbers 1]
      
      if {$voltage >= $min && $voltage <= $max} {
          puts "Result: True\n"
      } else {
          puts "Result: False\n"
      }

      Since the script always returns “Result: True” or “Result: False”, you can use a Status Expression to check for this string in the Standard Output stream and set the step status accordingly.

       

      1. Create a new sequence file.
      2. Add a Call Executable step and name it: “Pass/Fail Test: IsVoltageInRange (Pass)”
      3. On the Step Settings pane, open the Call Settings tab.
      4. Set File Pathname to the appropriate IsVoltageInRange script.
      5. Switch to the Standard Input tab.
        • Change Input Method to String
        • Enter a passing range. For example: 2, 8.

       

      1. Go to the Standard Output tab.
        • Store the output in: Step.StdOutput.Text
      2. Create a Boolean local variable: Locals.isVoltageInRange
      3. On the Properties tab, open the Expressions category.
        • Post-Expression: Locals.isVoltageInRange = (Find(Step.StdOutput.Text, "Result: True") > 0) ? True : False 
        • Status Expression: Step.Result.Status = Locals.isVoltageInRange ? "Passed" : "Failed"

       

      1. In Additional Results, enable Standard Input and Standard Output so they appear in the report.
      2. Add a Custom Result:
        • Name: isVoltageInRange
        • Value to Log: Locals.isVoltageInRange
        • Type: Boolean
      3. Duplicate the step and rename it: “Pass/Fail Test: IsVoltageInRange (Fail)”
      4. Modify the Standard Input to force a failure. For example: 3, 4.
         

       

      1. Save the sequence file as PassFailTestStatusExpression.seq in the same folder as the script.
      2. Run the sequence. Your report should resemble the screenshot provided.

       

      [Back to TOC]

      Evaluating Script Results: Numeric Limit Test using <None> Adapter

      Earlier, we discussed how to capture a script’s output in TestStand using the Standard Output stream. Once this output is available in your sequence, TestStand allows you to evaluate it and determine the result of the test sequence. One way to do this is by using a Numeric Limit Test with the <None> Adapter to inspect the script’s output.

       

      The following example scripts simulate a voltage measurement by hardcoding the reading to 5 V and printing the value in the format:

      Perl: GetVoltage.pl
      #!/usr/bin/perl -w
      use strict;
      
      #Simulated Voltage
      my $voltage = 5;
      
      print "Voltage: " , $voltage, "\n"
      Python: GetVoltage.py
      #!/usr/bin/env python
      
      #Simulated Voltage
      voltage = 5
      
      print "Voltage:", voltage, "\n"
      Tcl: GetVoltage.tcl
      #!/bin/sh
      # -*- tcl -*-
      # The next line is executed by /bin/sh, but not tcl \
      exec tclsh "$0" ${1+"$@"}
      
      #Simulated voltage
      set voltage 5
      
      puts "Voltage: $voltage\n"

      Because the script always returns output in the format “Voltage: <voltage>”, you can use a Post-Expression to parse this string from the Standard Output stream and store the numeric value in a local variable. You can then apply a Numeric Limit Test to evaluate the voltage value.

       

      1. Create a new sequence file.
      2. Add a Call Executable step and name it GetVoltage.
      3. In the Step Settings pane, open the Call Settings tab.
        • Set File Pathname to the appropriate GetVoltage script.
      4. Open the Standard Output tab.
        • Store the output in the variable: Step.StdOutput.Text
      5. Create a numeric local variable: Locals.voltage
      6. In the Properties tab, select Expressions.
        • Add the following Post-Expression to parse the voltage value: 

      Locals.voltage = Val( Mid( Step.StdOutput.Text, Find(Step.StdOutput.Text, "Voltage: ") + Len("Voltage: "), Find(Step.StdOutput.Text, "\n", Find(Step.StdOutput.Text, "Voltage: ")) - (Find(Step.StdOutput.Text, "Voltage: ") + Len("Voltage: ")))) 

       

      1. In Additional Results, enable Standard Output using Add Result From List.
        • This includes the stdout stream in the report.
      2. Add a Custom Result:
        • Name: Voltage
        • Value to Log: Locals.voltage
        • Type: Number

             

            1. Add a Numeric Limit Test step using the <None> Adapter.
              • Name it: Numeric Limit Test: IsVoltageInRange (Pass)
              • Set Data Source to Locals.voltage
              • Set limits that include 5 (e.g., Low: 3, High: 8)
            2. Duplicate both steps.
              • Rename the second Numeric Limit Test: Numeric Limit Test: IsVoltageInRange (Fail)
              • Adjust the limits so that the test fails (e.g., Low: 3, High: 4)

             

            1. Save the sequence file as NumericLimitTestNoneAdaptor.seq in the same folder as the scripts.
            2. Run the sequence. Your report should resemble the example shown below:

               

              [Back to TOC]

              Handling Script Errors in TestStand

              TestStand provides access to the Standard Error (stderr) stream, which allows your Perl, Python, or Tcl scripts to send error information directly to TestStand. By leveraging this capability, you can gracefully detect and handle script errors within your sequence.

               

              This is a modified version of the AddNumbersStdIn script. It validates that all inputs are numeric; if a non‑numeric value is detected, the script outputs an error message to stderr and exits with ExitCode −1.

              Perl: AddNumbersWithErrorHandling.pl
              #!/usr/bin/perl -w
              use strict;
              
              print "Enter numbers (separate with commas): ";
              my $numbersAsString = <STDIN>;
              my @numbers = split(/, | |,/,$numbersAsString);
              
              my $sum = 0;
              foreach my $currentNumber (@numbers)
              {
                  die("Input is not a number!, stopped") unless ($currentNumber =~ /^\d+$/);
                  $sum += $currentNumber ;
              }
              
              print "Sum: ", $sum, "\n";
              Python: AddNumbersWithErrorHandling.py
              #!/usr/bin/env python
              import sys
              
              try:
                  numbers = input('Enter numbers (separate with commas): ')
              except:
                  print >> sys.stderr, 'Input is not a number!'
                  sys.exit(-1)
              
              sum = 0
              for currentNumber in numbers:
                  sum = sum + currentNumber
              
              print "Sum:", sum, "\n"
              Tcl: AddNumbersWithErrorHandling.tcl
              #!/bin/sh
              # -*- tcl -*-
              # The next line is executed by /bin/sh, but not tcl \
              exec tclsh "$0" ${1+"$@"}
              
              puts "Enter numbers (separate with commas): "
              gets stdin numbersAsString
              
              set numbers [split $numbersAsString ,]
              
              set sum 0
              foreach currentNumber $numbers {
                  if ![string is integer -strict $currentNumber] {
                      #error "Input is not a number!"
                      puts stderr "Input is not a number!"
                      return -1
                  }
                  set sum [expr $sum + $currentNumber]
              }
              
              puts "Sum: $sum\n"
              TestStand makes it straightforward not only to capture the contents of the Standard Error stream but also to use this information to make decisions and properly handle errors.
               
              1. Create a new sequence file.
              2. Add a Call Executable step and name it “Call AddNumbers Script (Correct Input)”.
              3. In the Step Settings pane, open the Call Settings tab.
              4. Set File Pathname to the appropriate AddNumbersWithErrorHandling script.
              5. Switch to the Standard Input tab.
                • Change Input Method to String.
                • Enter comma‑separated numeric values (e.g., 2, 5, 8).
              6. Open the Standard Output tab.
                • Store output in Step.StdOutput.Text.
              7. Enable Standard Error:
                • Set Error Destination to Store in Value/Property.
                • Use the default location: Step.StdError.Text.

                         

                        1. Check Set Error.Msg to Standard Error Text.
                        2. Set If Standard Error is Non‑Empty to Set Step Status to Error.
                        3. In the Properties tab, select Additional Results.
                          • Add Standard Input, Standard Output, and Standard Error.

                         

                        1. Copy the step and place it after the original.
                          • Rename it “Call AddNumbers Script (Incorrect Input)”.
                          • Modify the Standard Input to intentionally trigger an error (e.g., 2, Five, 8).

                           

                          1. Save the sequence as HandlingScriptErrors.seq in the same folder as the scripts.
                          2. Run the sequence. Your report should appear similar to the following screenshot.

                             

                            [Back to TOC]

                            Next Steps

                            Now that you know how to integrate simple scripts into TestStand sequences, continue to Part 3 to learn how to create more advanced scripts that can call DLLs, perform data acquisition with NI‑DAQmx, and communicate with instruments using NI‑VISA. If you are new to scripting or do not yet have an interpreter installed, please refer to Part 1.