http://qs321.pair.com?node_id=646136


in reply to Sourcing shell scripts

Unless I am misunderstanding what you are doing,

use Env;
should give you everything you need. On Windows, I can set environment variables from inside perl via $Env{var}=<value>, and these environment variables will be visible to subsequent `backtick` calls.

Replies are listed 'Best First'.
Re^2: Sourcing shell scripts
by tuxz0r (Pilgrim) on Oct 20, 2007 at 05:55 UTC
    I can always set an environment variable using the built in %ENV on Unix (or you mention 'use Env' on Windows) but the idea was to make use of our existing shell environment (which is built dynamically when our software package is installed) so we can have a single source of environment settings (easier to debug, modify, etc.). We needed these shell environments set outside of the Perl script and we didn't want to duplicate them by having another Perl script to set the environment just for Perl.

    The code snippet posted will source this shell environment file prior to exec'ing the Perl script, that way it's available to the Perl code. We don't run these programs by hand, they run from a cron job, and we previously had to write a shell wrapper to perform the same function that the snippet does automatically for us. Plus, now any of our shell debugging tools and utilities are using the exact same environment settings as the actual Perl scripts that run the system. Which was the whole point.

    I hope this makes sense.