bkimelman has asked for the wisdom of the Perl Monks concerning the following question:

At the office we run an AIX ver 5 rel 3 system. We have a Perl script that given its parameters makes a decision on how to call several other programs. One of the programs that it calls is a compiled C program. I was having problems so I investigated and found that an environment variable that is known to the Perl script is not received by the compiled C program. The Perl script uses the Perl 'system' function to run the compiled C program. According to the information I found for AIX the limit of parameters and environment variables is very large for our system, so that is not the problem.

Any ideas as to why an environment variable gets lost when the C program is called ?

Replies are listed 'Best First'.
Re: Problem with Perl 'system' comand
by MidLifeXis (Monsignor) on May 26, 2010 at 16:44 UTC

    Without knowing the application or the environment variables not being set, this question is just a shot in the dark: is the C program setuid or setgid?

    For security, certain variables are cleansed from the environment for setuid or setgid applications. Among them are PATH, LD_LIBRARY_PATH, and others.

    --MidLifeXis

Re: Problem with Perl 'system' comand
by graff (Chancellor) on May 26, 2010 at 17:41 UTC
    I've never been on an AIX system, but since it's "based on" unix, I would check whether the env. variable is marked for "export" when it is set. This may have more to do with the shell you're using (to run the perl script), rather than the OS.

    In bourne-type shells, it's a difference between:

    # setting an unexported env. variable: VARIABLE='some value' # vs. export VARIABLE='some value' # or VARIABLE='some value' export VARIABLE
Re: Problem with Perl 'system' comand
by lorn (Monk) on May 26, 2010 at 16:42 UTC

    Because system comand create another bash process for STDOUT/STDERR, so your local variable probably does not exits.

    Try to pass the variable in the system() call, like:

    system("LANG=Perl /usr/bin/my_c_program");
      The environment is usually inherited from the parent