NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I read an environment variable in TestStand 3.5?

Hi,

 

I'm new to TestStand. I would like to be able to read an environment variable and place within a TestStand 3.5 'locals' variable

Can this be done? If so, how?

 

Thanks

Alan

0 Kudos
Message 1 of 4
(5,465 Views)

Hi Alan

 

I have not used the enviroment variables before but am assuming you will use the windows api function GetEnvironmentVariable to return the value of the variable you want. This api call would be done in a code module from the IDE of your choice, with the variable string defined as an output of the module.

 

 

Make sure that you have created a new string variable in the locals container. The next step would be to insert an action step into your TestStand sequence with the code module refered to above specified. You do this by clicking 'Specify Module...' ontthe General tab of the action step properties.

 

Once the code module has been specified, TestStand will allow you to configure the parameters that define how the data is passed in and out of the code module.All you need to is enter "Locals.*name of your local variable*" in the 'Value for the parameter, this will tell TestStand to immediately store the value from your code module in the local variable. See the image below.

 

configure step.JPG

 

 I hope this helps, let me know if you have any more questions.

 

Rich

 

NI | UK

0 Kudos
Message 2 of 4
(5,445 Views)

It's actually even easier than that.  You can call the Windows API directly from TestStand by calling into the dll that hosts the function you want to use.  In this case, the dll is Kernel32.dll.

 

Simply use the C/C++ Adapter and point to that file.  You will need to define the function prototype yourself, but if you find the Microsoft documentation for the API you want to use, this is usually easy.

 

Here's a step set up to read an environment variable, and return its value (up to 1024 characters).

Environment Variable.JPG

 

One other note is that many Windows API functions have a post-fix of A or W.  The A stands for ASCII and the W for Unicode.  In Visual Studio, the compiler automatically chooses which one to use, but if you call into the DLL directly, you get the choice of which one to use.  If your environment variable is ascii text, you can use the A version, but if it contains unicode text (for instance, on a non-english version of Windows) you should use the W version.

Josh W.
Certified TestStand Architect
Formerly blue
Message 3 of 4
(5,429 Views)
Fantastic - thanks for your help!
0 Kudos
Message 4 of 4
(5,419 Views)