Skip to main content

Summary This article clarifies how to access environment variables from the Orbix configuration.
Environment

Orbix 6.3

Windows Operating Systems

Question/Problem Description

How to access environment variables from the Orbix configuration?

Is it possible to access environemnt variables from within the Orbix configuration file or configuration repository?

Clarifying Information
Error Message
Defect/Enhancement Number
Cause
Resolution

Orbix does not provide direct access to Windows environment variables from within the Orbix configuration or configuration repository.

Defining a following statement in the Orbix configuration does not work:

MY_USER_DIR = "C:\\Users\\%USERNAME%";

Workaround

A possible workaround is to pass the variable into the process via the -ORB parameter, e.g as follows:

> server.exe -ORBMY_USER_DIR C:\\Users\\%USERNAME%

The code snipped below shows how to access this variable from the server mainline:

...

#include <orbix/configuration.hh>

...

int main( int argc, char* argv[] )
{
  try
  {
    cout << "Initializing the ORB" << endl;
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    // Get our configuration and defaults
    CORBA::Object_var cfg_ref;
    cfg_ref = orb->resolve_initial_references("IT_Configuration");
    IT_Config::Configuration_var cfg = IT_Config::Configuration::_narrow(cfg_ref);
    
    CORBA::String_var s;
    cfg->get_string("MY_USER_DIR",s);
    cout << "MY_USER_DIR: " << s << endl;
    ...
  }
}

Running the above code will produce the following output:

>server -ORBMY_USER_DIR c:\\Users\\%USERNAME%

Initializing the ORB
MY_USER_DIR: C:\\Users\\testusr

Notes
Attachment

#Orbix
#KnowledgeDocs