NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read environment variable

How do I read an environment variable within TS?

 

I was thinking of calling getenv("VARIABLE_NAME") except it returns a char * and TS only allows Boolean or Numeric return type.

I wonder if LV has any function for doing the same thing. 

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

Hi,

 

You can pass a string back to TestStand but you have to use a return parameter eg int MyTest(char *environment_name);

 

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 2 of 5
(4,169 Views)

Terago,

 

You can use a .NET step to invoke a method named "GetEnvironmentVariable(string)" from System.Environment class in mscorlib.dll (you can find this dll in your Windows directory in Microsoft.NET\Framework\v2.0.xxx folder (depending on the version).

 

This method needs an input parameter - that's a string holding environment variables name (like PATH or COMSPEC), it's return value - also a string - in which you'll find variables value, following method invocation.

 

Hope this helps.

 

Regards

0 Kudos
Message 3 of 5
(4,164 Views)

miniMe: I don't see System.Environment class in mscorlib.dll (v2.0.50727)

 

I found a VI from the LV forum, UES Read Environmental Variables.vi, in this thread

http://forums.ni.com/ni/board/message?message.uid=795994

I

It has some predefined enumerated type for the common variables or you can pass a variable string to it, seem to be working fine.

 

Thanks for all your help.

0 Kudos
Message 4 of 5
(4,156 Views)

With the new ability in TestStand 4.2 to get the standard output from a command line, you can do this with a call executable step.

 

Simply call cmd.exe as the executable, and pass it the following expression.  Then all you have to do is set Locals.EnvironmentVariableName to the name of the environment variable you want the value of and define where you want the standard output to be stored.

"/C \"echo %"+Locals.EnvironmentVariableName+"%\""

 

I'm attaching a sequence file that shows this.  The attachment is necessarily saved in TestStand 4.2, since it uses a feature introduced in that version.

Josh W.
Certified TestStand Architect
Formerly blue
Message 5 of 5
(4,137 Views)