Sometimes 3rd party software (like Softimage) has scripts you have to 'source'
to set up a bunch of environment variables.
For exmaple, Softimage gives you a DOS batch file for windows (setenv.bat),
and a CSH file for unix (eg, .xsi_4.0).
Often one is confronted with the problem of getting these environment settings
set into a perl script's environment.
One 'clean' way to do it is shown as follows, which invokes a shell to
load the file, then print the environment settings out in VAR=VALUE format,
that the perl script can then parse easily:
# LOAD SOFTIMAGE'S 'setenv.bat' FILE SETTINGS INTO PERL ENVIRONMENT
sub LoadSoftimageDOS()
{
my $vars = `cmd /c "call C:\\Softimage\\XSI_4.0\\Application\\bin\\setenv.bat && set"`;
foreach ( split(/\n/, $vars) )
{
if ( /(^[^=]*)=(.*)/ ) { $ENV{$1} = $2; }
}
}
# LOAD SOFTIMAGE'S CSH FILE INTO PERL ENVIRONMENT
sub LoadSoftimageLINUX()
{
my $vars = `csh -fc 'source /usr/Softimage/XSI_4.0/.xsi_4.0; printenv'`;
foreach ( split(/\n/, $vars) )
{
if ( /(^[^=]*)=(.*)/ ) { $ENV{$1} = $2; }
}
}
|