How to read an environment variable? - VxWorks

This is a discussion on How to read an environment variable? - VxWorks ; Hi all, I have a script that creates the environment variable TEST = "test", and then it starts a task that should read this variable and print it, but I can't make it work. The code I'm using is the ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: How to read an environment variable?

  1. How to read an environment variable?

    Hi all,

    I have a script that creates the environment variable TEST = "test",
    and then it starts a task that should read this variable and print it,
    but I can't make it work. The code I'm using is the following one. Any
    ideas about what is wrong?

    Thanks,

    Andre

    #include

    void printEnv()
    {
    if( envLibInit( false ) == ERROR )
    {
    return;
    }

    strcpy( var, getenv( "TEST" ) );
    printf( "%s", var );
    }


  2. Re: How to read an environment variable?

    sieg1974@yahoo.com wrote:

    >Hi all,
    >
    >I have a script that creates the environment variable TEST = "test",
    >and then it starts a task that should read this variable and print it,
    >but I can't make it work. The code I'm using is the following one. Any
    >ideas about what is wrong?
    >
    >Thanks,
    >
    >Andre
    >
    >#include
    >
    >void printEnv()
    >{
    > if( envLibInit( false ) == ERROR )
    > {
    > return;
    > }
    >
    > strcpy( var, getenv( "TEST" ) );
    > printf( "%s", var );
    >}


    Your example doesn't call putenv() to set the environment variable
    "TEST". You might also want to add a call to printf() that announces
    when envLibIinit() returns ERROR.

    --
    ================================================== ======================
    Michael Kesti | "And like, one and one don't make
    | two, one and one make one."
    mrkesti at comcast dot net | - The Who, Bargain

  3. Re: How to read an environment variable?

    Hi all,

    I found out that the enviroment variable TEST should be set in the
    following way by the script

    putenv( "TEST = test" )

    and the code to read it should not use envLibInit.

    void printEnv()
    {
    char * var = getenv( "TEST" );
    printf( "%s", var );
    }


    sieg1974@yahoo.com wrote:
    > Hi all,
    >
    > I have a script that creates the environment variable TEST = "test",
    > and then it starts a task that should read this variable and print it,
    > but I can't make it work. The code I'm using is the following one. Any
    > ideas about what is wrong?
    >
    > Thanks,
    >
    > Andre
    >
    > #include
    >
    > void printEnv()
    > {
    > if( envLibInit( false ) == ERROR )
    > {
    > return;
    > }
    >
    > strcpy( var, getenv( "TEST" ) );
    > printf( "%s", var );
    > }



+ Reply to Thread