NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Tourbleshooting passing arguments to scripts

Hi,

 

I am new to TestStand and have been through the tutorials and some white papers, but I have run into a problem.

 

I have inherited a production script that uses Python scripts. Currently there is a workaround to run and load results from Python scripts into TestStand, but I have read that this is not required here: http://www.ni.com/tutorial/8847/en/#toc5 . Following the instructions, I am able to run scripts and parse outputs. However, I am having trouble with "Passing Data to Scripts from TestStand: Command Line". Any values in the Argument Expression of the Call Settings of the Call Executable step that calls the Python script directly do not get passed to the script. if I call it directly. E.g. if I call the script as follows:

File Pathname: sum.py

Argument Expression: "2 5 8"

 

Then the script is run, but the arguments 2, 5 and 8 are not passed to the script. However, if I call Python (full disclosure, we are using a standard installation of Python 3.3) instead, passing the script as a parameter, as follows:

 

File Pathname: c:\Python33\python.exe

Argument Expression: "sum.py 2 5 8"

 

Then the script is called with the arguments.

 

Does anyone have any experience with this and/or any advice? I can call Python directly, but would prefer to simplify things where possible.

 

Thanks,

David

 

0 Kudos
Message 1 of 9
(6,117 Views)

Hi David,

 

What value is returned when you run the sequence? 

It looks like the example script in the tutorial that you linked is missing parenthesis around the "Sum:", sum, "\n". I see the same behavior that you describe until I add the parenthesis, then the correct value is returned. 

If you use the example in the tutorial and add the parenthesis do you still see this behavior?

 

Regards

Carli S.
Troubleshooting & Maintenance Digital Business Manager - NI
0 Kudos
Message 2 of 9
(6,069 Views)

Hi Carli,

 

Thank you for getting back to me (and my apologies about the title 😄 ). I checked on the parentheses, and they are there. In my test sequence I run the script 2 ways and get the following results:

 

1.

File Pathname: c:\Python33\python.exe

Argument Expression: "sum.py 2 5 8"

(Result) Standard Output: Hello 2, 5, 8, Sum: 15 

 

2.

File Pathname: sum.py

Argument Expression: "2 5 8"

(Result) Standard Output: Hello Sum: 0 

 

The script sum.py is as follows:

 

#!/usr/bin/env python
import sys

print("Hello")

#Command Line Argument 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)):
    print(sys.argv[n] + ', ')
    sum = sum + int(sys.argv[n])

print("Sum: " + str(sum))

The additional prints are there to show things working. Like I say, I'm not sure if this is due to the Python version (3.3) or not, but the arguments don't seem to be passed to the script when calling the script directly. I am curious to know what I am doing wrong. Please let me know if you require the sequence file.

 

Regards,

David

 

 

0 Kudos
Message 3 of 9
(6,059 Views)

David,

 

Can you attach the sequence file that you are using? 

When I use the script that you have attached with python 3.3.3 and TestStand 2014 it appears to function properly. So the problem may be caused by something in your sequence file.

 

 

Regards

Carli S.
Troubleshooting & Maintenance Digital Business Manager - NI
0 Kudos
Message 4 of 9
(6,039 Views)

Hi Carli,

 

Please find attached! I'm keen to hear where things have gone wrong. 🙂

 

Thanks,

David

0 Kudos
Message 5 of 9
(6,012 Views)

Aaaand now for the Python script in question (which will only be attached if I make it a .txt)...

0 Kudos
Message 6 of 9
(6,011 Views)

Hi David,

 

Thank you for attaching your code.

 

Is there a reason that you need the "Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> " at the top of your sum.py file?

I'm not very familar with python, however when I created scripts to test the functionally I did not have those lines. When I ran your program with them I see the same behavior that you do. But, when I remove those lines from the file that you attached, the program appears to function correctly. 

 

If you remove those lines do you see the expected behavior?

 

Regards

Carli S.
Troubleshooting & Maintenance Digital Business Manager - NI
0 Kudos
Message 7 of 9
(5,987 Views)

Hi Carli,

 

Thank you for checking and sorry for the delay. I'm not sure where you saw the "Python 3.3.3..." string. I can't see it in what I posted, my script or sequence. However, it appears to be the opening lines of the Python interactive shell. And I'm not sure why it is being called that way. Where did you see that string?

 

Regards,

David

0 Kudos
Message 8 of 9
(5,935 Views)

Hi David,

 

When I opened your sum.py file in python I see those lines above the code. If I copy and paste your python code into a new .py file and call that file using your sequence file it appears to function properly.

 

Regards

Carli S.
Troubleshooting & Maintenance Digital Business Manager - NI
0 Kudos
Message 9 of 9
(5,922 Views)