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

Hi Monks

I'm executing a shell script from my perl script to set up the Environment

Need help to understand that how can I use the values that have been set by the shell in my current perl script

my $SID=shift; my $cmd="ksh /my_location/switchdb.ksh $SID"; system($cmd);

The above sets up value for ORACLE_HOME

But i'm still am not able to get that value back if i'm using $ENV{ORACLE_HOME}

Any help will be really appreciated.

Thanks, Anubhav

Replies are listed 'Best First'.
Re: Environment setting using shell
by Corion (Patriarch) on Jul 08, 2016 at 09:26 UTC

    See Get default login environment and its replies. Basically, you will have to append a command to output the effective environment of the child and read that output back in in the parent.

Re: Environment setting using shell
by FreeBeerReekingMonk (Deacon) on Jul 08, 2016 at 15:19 UTC
    What if you try this?

    my $SID=shift; my $output=`. /my_location/switchdb.ksh $SID 2>/dev/null 1>/dev/null & +& echo \$ORACLE_HOME`; chomp($output); if($output =~ m{/}){ $ENV{ORACLE_HOME} = $output; } print "DEFINED ORACLE_HOME as (" . $ENV{ORACLE_HOME} . ")\n";

    Note that I do not execute, I source the script. Then request the variable with and (&&)

    in a similar fashion, if you need more environment variables, dump them with env:

    my $output=`. /my_location/switchdb.ksh $SID 2>/dev/null 1>/dev/null & +& env > /tmp/$mytempfile`;

    then read the file back and split(/=/,$line,2) to get the key and the value, and put them in %ENV