Changeset 23306


Ignore:
Timestamp:
2010-11-09T19:56:43+13:00 (11 years ago)
Author:
sjm84
Message:

setup_greenstone_evn sub to help set up the environment if GSDLHOME and GSDLOS are already known. This perl subrouting will call setup.bash/bat and manually set the environment vars that setup would normally set. May need expanding if we want to restrict things to only those environment vars that the Greenstone setup script sets.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/util.pm

    r23285 r23306  
    13741374}
    13751375
     1376# Subroutine that sources setup.bash, given GSDLHOME and GSDLOS and
     1377# given that perllib is in @INC in order to invoke this subroutine.
     1378# Call as follows -- after setting up INC to include perllib and
     1379# after setting up GSDLHOME and GSDLOS:
     1380#
     1381# require util;
     1382# &util::setup_greenstone_env($ENV{'GSDLHOME'}, $ENV{'GSDLOS'});
     1383#
     1384sub setup_greenstone_env() {
     1385    my ($GSDLHOME, $GSDLOS) = @_;
     1386
     1387    #my %env_map = ();
     1388    # Get the localised ENV settings of running a localised source setup.bash
     1389    # and put it into the ENV here.
     1390    my $perl_command = "(cd $GSDLHOME; . ./setup.bash > /dev/null; env)";
     1391    if($GSDLOS =~ m/windows/i) {
     1392        #$perl_command = "(cmd && cd $GSDLHOME && setup.bat > nul && set && exit)";
     1393        $perl_command = "(cd $GSDLHOME && setup.bat > nul && set)";
     1394    }
     1395    if (!open(PIN, "$perl_command |")) {
     1396        print STDERR ("Unable to execute command: $perl_command. $!\n");
     1397    }
     1398
     1399    while (defined (my $perl_output_line = <PIN>)) {
     1400        my($key,$value) = ($perl_output_line =~ m/^([^=]*)[=](.*)$/);
     1401        #$env_map{$key}=$value;     
     1402        $ENV{$key}=$value;
     1403    }
     1404   
     1405    # If any keys in $ENV don't occur in Greenstone's localised env
     1406    # (stored in $env_map), delete those entries from $ENV
     1407    #foreach $key (keys %ENV) {
     1408    #   if(!defined $env_map{$key}) {
     1409    #       print STDOUT "**** DELETING ENV KEY: $key\tVALUE: $ENV{'$key'}\n";
     1410    #       delete $ENV{$key}; # del $ENV(key, value) pair
     1411    #   }
     1412    #}
     1413    #undef %env_map;
     1414}
     1415
    137614161;
Note: See TracChangeset for help on using the changeset viewer.