05-28-2009 03:38 PM
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.
05-29-2009 01:51 AM
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
05-29-2009 06:23 AM
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
05-29-2009 07:02 AM
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.
05-29-2009 04:12 PM
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.