10-21-2016 09:36 AM
Calling the attached .py script from teststand does not work (exit code 1)
Executing directly - it works !
Removing the line "f = open('debug2.txt', 'w')" - makes it work also from Teststand (exit code 0).
I have other more complicated script which also works when executing directly, but not from teststand (exit code 1).
What is going on ?
import sys
f = open('debug2.txt', 'w')
#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")
Solved! Go to Solution.
10-24-2016 02:59 AM
I guess that you working directory is not the directory where the Python script is located when you run from teststand. When I run a batch file from teststand, one of the first commands that are executed is PUSHD "%~dp0" to switch to the batch file folder as working directory, so the other files in this directory can be used without absolute paths. I don't know how to do this in Python.
10-24-2016 04:00 AM
Hello again!
Exit code 1 indicates a Command-line Error. Are you running it by setting the file pathname in 'call settings' as the location of python, and then putting the argument expression 'AddNumbersCommandLine.py'? And what are you setting the working directory as? Svh's suggestion sounds like a good one - is debug2.txt in the same folder as your sequence file?
When I run it from TestStand, it works and I get the correct output, see screenshot for how I did it.
Let me know if this works!
Best regards,
Leah
10-24-2016 04:16 AM
It is in fact related to "working directory". I've been struggling with that before with teststand.
when hardcoding the path
or changing
"os.getcwd()"
to
"os.path.dirname(os.path.realpath(sys.argv[0]))"
my python scripts are also working from Teststand