Re: exec problem
by jasonk (Parson) on Mar 13, 2003 at 20:15 UTC
|
The exec is working fine, in fact it is working fine every single time the script runs, so you run the script, it sets the environment, then it runs the script, which sets the environment, then runs the script, and so on on forever.
| We're not surrounded, we're in a target-rich environment! |
|---|
| [reply] |
|
|
"A supercomputer is a machine that runs an infinite loop in two seconds" ;-)
If you don't have a supercomputer at hand, consider modifying @ARGV and checking it so you can differentiate between the first and the second instance of the program:
BEGIN {
unless ($ARGV[0] eq "-2ndcall") {
print "\n ... starting BEGIN\n";
$ENV{LD_LIBRARYN32_PATH} = qw(
/usr/path1
/opt/path2);
unshift @ARGV, "-2ndcall";
exec 'env', $^X, $0, @ARGV;
}
}
Update: Fixed stupid mistake. | [reply] [d/l] |
Re: exec problem
by dws (Chancellor) on Mar 13, 2003 at 23:02 UTC
|
| [reply] [d/l] [select] |
|
|
perl -e '
$ENV{"FOO"} = "bar";
exec "env";
'
sets the environment variable just fine for me on FreeBSD (as seen in env's output). No need to fork here. | [reply] |
|
|
It works with exec. I have some scripts which set ORACLE_HOME and LD_LIBRARY_PATH like so:
BEGIN {
unless ($ENV{BEGIN_BLOCK}) {
$ENV{ORACLE_HOME} = "/oracle/product/current";
$ENV{LD_LIBRARY_PATH} = "$ENV{ORACLE_HOME}/lib";
$ENV{BEGIN_BLOCK} = 1;
exec $^X, $0, @ARGV;
}
}
This works fine. Careful readers will see that I don't exec env. It doesn't appear to be necessary.
| [reply] [d/l] |
|
|
Here's a fix to the exec problem!!!
BEGIN {
my $path_aref = "/u/wwsmith/pkg/ngt/lib",<br>
"/u/wwsmith/pkg/globus-2.0-gcc-3.1.1/lib",<br>
"/u/wwsmith/pkg/xerces-c-1_7_0-gcc-3.1.1/lib",<br>
"/u/wwsmith/pkg/cppunit-1.8.0-gcc-3.1.1/lib",<br>
"/u/wwsmith/pkg/gcc-3.1.1/lib",<br>
"/usr/local/pkg/globus/2.0/lib",<br>
"/opt/scsl/scsl/usr/lib32/mips4",<br>
"/opt/scsl/scsl/usr/lib32",<br>
"/opt/mpt/mpt/usr/lib32/mips4",<br>
"/opt/mpt/mpt/usr/lib32",<br>
"/opt/MIPSpro/MIPSpro/usr/lib32/mips4",<br>
"/opt/MIPSpro/MIPSpro/usr/lib32" ;
foreach my $path ( @$path_aref ) {
my $ld = $ENV{LD_LIBRARYN32_PATH};
if( ! $ld ) {
$ENV{LD_LIBRARYN32_PATH} = $path;
} elsif( $ld !~ m#(^|:)\Q$path\E(:|$)# ) {
$ENV{LD_LIBRARYN32_PATH} .= ':' . $path;
} else {
$path = "";
}
if( $path ) {
exec 'env', $^X, $0, @ARGV;
}
}
}
| [reply] |
Re: exec problem
by Vorlin (Beadle) on Mar 14, 2003 at 01:59 UTC
|
It seems like your exec is in perpetual looping for some reason. I didn't have time to look at it too much but if you do the following, it runs through once and exits out of the BEGIN loop.
Change:
exec 'env', $^X, $0, @ARGV;
to:
exec 'env', $^X, $0, @ARGV if 0;
After that loops once, $ENV{'LD_LIBRARYN32_PATH'} will be populated with what you need.
Edit: added proper breaks and such because I was an idiot yesterday and forgot how to format! | [reply] [d/l] [select] |
|
|
Looks like I need to take typing lessons all over again!
I forgot to add that at the end of the first loop, the
BEGIN statement is finished and it exits out. But that's
probably already known, hehe...
| [reply] |
Re: exec problem
by bart (Canon) on Mar 15, 2003 at 17:20 UTC
|
The reason why it "hangs", is because you're having a case of endless recursion: there is no condition on which the function doesn't recurse.
But I'm not sure why you're using env. What does it buy you that simply setting %ENV and continuing with the rest of the script, wouldn't? | [reply] |