Sourcing Unix environment file? 
Author Message
 Sourcing Unix environment file?

Hi,

I am trying to source in a Unix environment file from a perl script, but
was unable to do so.

Here is the problem:

at the Unix prompt, one can type

$ . /etc/navenv.d/DBSEnv

and it would read the DBSEnv file and set the appropriate environment
parameters.

I have tried using the system and exec commands, but none of it works.
e.g

$cmd = ". /etc/navenv.d/DBSEnv";
system ($cmd);

I have tried to overwrite the special metacharater "." by preceding the
"." with the "\", and it still did not work.

Have anyone run into this problem before?  And if you have, how would
you resolve it? Any suggestions will be appreciated.  Thank you.

Regards,

Thuy



Sun, 05 Nov 2000 03:00:00 GMT  
 Sourcing Unix environment file?

Quote:

> Hi,

> I am trying to source in a Unix environment file from a perl script, but
> was unable to do so.

> Here is the problem:

> at the Unix prompt, one can type

> $ . /etc/navenv.d/DBSEnv

> and it would read the DBSEnv file and set the appropriate environment
> parameters.

> I have tried using the system and exec commands, but none of it works.
> e.g

> $cmd = ". /etc/navenv.d/DBSEnv";
> system ($cmd);

> I have tried to overwrite the special metacharater "." by preceding the
> "." with the "\", and it still did not work.

> Have anyone run into this problem before?  And if you have, how would
> you resolve it? Any suggestions will be appreciated.  Thank you.

> Regards,

> Thuy

Need some trickery to get the environment (say a .cshrc, or other
'setenv ...'
command file) into perl's %::ENV; using something like this (if the

  open(CSH_OVERLOADING_FH, "/bin/csh -cf 'source $csh_file_s >>&!
/dev/null; env' |") ||
    return (-2, "$routine_s: failed open(/bin/csh -cf 'source
$csh_file_s >>&! /dev/null; env' |)");

  while (<CSH_OVERLOADING_FH>) {
    chomp;

    ;# key=value pairs (e.g., environment vars).
    if (/^(\S+)=(.*)/) {
      $key_s = $1;
      $val_s = $2;
      $::ENV{$key_s} = $val_s;
    }

    ...

Be careful and use this only on benevolent csh files.

Silvio



Mon, 06 Nov 2000 03:00:00 GMT  
 Sourcing Unix environment file?

Quote:


> > Hi,

> > I am trying to source in a Unix environment file from a perl script, but
> > was unable to do so.

> > Here is the problem:

> > at the Unix prompt, one can type

> > $ . /

> > and it would read the DBSEnv file and set the appropriate environment
> > parameters.

> > I have tried using the system and exec commands, but none of it works.
> > e.g

> > $cmd = ". /etc/navenv.d/DBSEnv";
> > system ($cmd);

> > I have tried to overwrite the special metacharater "." by preceding the
> > "." with the "\", and it still did not work.

> > Have anyone run into this problem before?  And if you have, how would
> > you resolve it? Any suggestions will be appreciated.  Thank you.

> > Regards,

> > Thuy

do the following.

require "dotsh.pl";

$ENV{SHELL} = "/bin/sh"; # or what ever shell you are using.

&dotsh("/etc/navenv.d/DBSEnv");

Hope this helps.

John C. Quillan

- Show quoted text -

Quote:
> Silvio



Mon, 20 Nov 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help please with sourcing an environment variable

2. parse mail files:beginning Perl in UNIX environment

3. sourcing (bash) config files within perl

4. Problems with sourcing a file

5. Problems with sourcing a file in perl.

6. workaround for sourcing file from perlscript

7. sourcing a file in Perl

8. sourcing (bash) config files within perl

9. Sourcing files from my perl script

10. Accessing Unix Environment Variables from a Perl Script

11. Resolve UNIX environment variable within an array

12. Parsing Unix mbox in MS Environment

 

 
Powered by phpBB® Forum Software