Quantcast
Channel: NI TestStand topics
Viewing all articles
Browse latest Browse all 6730

Python Step // Cannot run python script from its current location

$
0
0

Hi all,

I need to run a python script from a sequence using the python step found here.

My sequence looks like this:

sequence.png

Both TS-DummyGateway.py and TS-OtherDummyGateway.py contain the following code:

import sys
import datetime
import os

def hello():
	return "Hello, now is : "  + str(datetime.datetime.now()) + "& current dir :" + str(os.getcwd());

The sequence calls both python script and display their return messages.

The python step setup:

pythonStepConfig.png

Both steps have the same config besides the python file path.

 

When running the sequence I am expecting the python script to display its current location (ie the location of the .py file), instead of that I am getting the folder where the sequence is located. In order to fix it I just need to config the step and select again the python script that is in the field "file path". When I then run the sequence again I can this time see the proper python script location being displayed on screen.

If I close TestStand and re-open it will misbehave again and I have to do that trick (select the script that is already picked in "file path") to make it work.

Finally, when I fix one of the python steps, both will display the folder of the one that just got fixed, it is not possible for them to display separate folders.

 

My interpretation: when TestStand is opened it selects by default its surrounding folder as environement, when I select a python script this environement changes to the folder containing the script, and so on for each script changes.

 

What I would like: for python to run from where it is located.

 

Has anyone any idea on how to do that? I cannot be the only that has come across this problem.

 

Thanks in advance for any tip ! Smiley Happy

 

Attached is the Sequence and both python files, you will need to put them wherever you like in your file system and configure the sequence accordingly.


Viewing all articles
Browse latest Browse all 6730

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>