in reply to exec problem

I'm trying to pre-load the LD_LIBRARYN32_PATH via exec call (see below) and my script's just sitting there spinning its wheels.

The description of %ENV in perlvar (for 5.6.1) reads:

The hash %ENV contains your current environment. Setting a value in ENV changes the environment for any child processes you subsequently fork() off.
There's no mention of %ENV in the description of exec() perlfunc. It's been my experience that if you want to change the environment, you need to fork() first, then exec().

Replies are listed 'Best First'.
Re: exec problem
by crenz (Priest) on Mar 14, 2003 at 00:31 UTC

    Executing

    perl -e '
    $ENV{"FOO"} = "bar";
    exec "env";
    '

    sets the environment variable just fine for me on FreeBSD (as seen in env's output). No need to fork here.

Re: Re: exec problem
by virtualsue (Vicar) on Mar 14, 2003 at 12:01 UTC
    It works with exec. I have some scripts which set ORACLE_HOME and LD_LIBRARY_PATH like so:
    BEGIN { unless ($ENV{BEGIN_BLOCK}) { $ENV{ORACLE_HOME} = "/oracle/product/current"; $ENV{LD_LIBRARY_PATH} = "$ENV{ORACLE_HOME}/lib"; $ENV{BEGIN_BLOCK} = 1; exec $^X, $0, @ARGV; } }
    This works fine. Careful readers will see that I don't exec env. It doesn't appear to be necessary.
Re: exec problem
by tejnil (Novice) on Mar 13, 2003 at 23:58 UTC