What's the idea here? You must run a sub-process to read the .cshrc file, because to read a .cshrc file, you have to run csh. So the sub-process is mandatory. But then you get the subprocess to spit out its environment, and you load in all the appropriate settings.open ENV, "csh /van/home/.cshrc; env |" or die ...; while (<ENV>) { chomp; my ($var, $val) = split /=/, $_ , 2; $ENV{$var} = $val; }
The only problem with this is that sometimes environment variables can contain newlines or other funny characters, in which case you may not be able to parse the output of the env command reliably. The easy way around this is to use your own reliable replacement for env instead of the real env. This is very easy:
Now the variables are terminated by \0 instead of \n, and to parse the environment data back in the main program, just use local $/ = "\0" when reading the output of myenv.# myenv for my $var (keys %ENV) { print $var, "=", $ENV{$var}, "\0"; }
This same trick works for /bin/sh scripts also, of course.
In reply to Re: Sourcing cshrc environment in Perl
by Dominus
in thread Sourcing cshrc environment in Perl
by Kirby
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |