Setting LD_LIBRARY_PATH env variable for child process

L

Lax

Hi all,
I'm trying to rewrite a Bourne shell script in Perl.
The shell script, among other things, sets the LD_LIBRARY_PATH and
CLASSPATH variables, exports them and kicks off a Java process.

LD_LIBRARY_PATH=NewLibPath; export LD_LIBRARY_PATH
CLASSPATH=NewClassPath; export CLASSPATH
$java JavaClass

This works fine and the new values for LIBPATH and CLASSPATH are
passed on fine to the Java process.
In my Perl rewrite, I'm doing,

$ENV{CLASSPATH}="NewClassPath" ;
$ENV{LD_LIBRARY_PATH}="NewLibPath";
system("$java JavaClass");

The CLASSPATH part works fine, but the new setting for LIB_PATH
doesn't seem to be working.
I also tried,

system("export LD_LIBRARY_PATH;$java -cp $ENV{CLASSPATH} JavaClass");

This too doesn't seem to have any effect.
A Google search on this issue shows this exchange on c.l.p.m,
http://tinyurl.com/333h64

I'm leaning towards setting LD_LIB_PATH from a shell wrapper around
the perl script, but I wonder
if there are more elegant ways of doing this? Does anyone have any
pointers for me?
Platform: The script would run on Linux , Solaris and AIX.

Thanks for your time,
Lax
 
B

Big and Blue

Lax said:
I'm trying to rewrite a Bourne shell script in Perl.
The shell script, among other things, sets the LD_LIBRARY_PATH and
CLASSPATH variables, exports them and kicks off a Java process.

Not sure why you would want to set LD_LIBRARY_PATH for Java and the
CLASSPATH can be set using the -cp command line option.
This works fine and the new values for LIBPATH

LIBPATH? See below - are you setting the right var on the right system.
Platform: The script would run on Linux , Solaris and AIX.

IIRC AIX uses something other than LD_LIBRARY_PATH (LIBPATH?) - (it
isn't known as Aix Isn't uniX for nothing).

This is something different - it refers to the fact that dynamic linking
is set up as a process *starts* and so a process itself can't set
LD_LIBRARY_PATH to affect its own linking. It can, however, set it so that
sub-processes are affected by it, which is what you are trying to do.

This simple script shows that it can be set:

=====
#!/usr/bin/perl
#
$ENV{LD_LIBRARY_PATH} = '/xyzzy';

system "echo \$LD_LIBRARY_PATH";
=====

so I suspect something else amiss in your script, which we haven't seen, so
can't help you with.
 
P

Peter J. Holzer

In my Perl rewrite, I'm doing,

$ENV{CLASSPATH}="NewClassPath" ;
$ENV{LD_LIBRARY_PATH}="NewLibPath";
system("$java JavaClass");

The CLASSPATH part works fine, but the new setting for LIB_PATH
doesn't seem to be working.

Should work. Are you sure that the LD_LIBRARY_PATH isn't exported and
not that it is ignored by $java?

For example, on Linux systems LD_LIBRARY_PATH is ignored if the
effective and real uid don't match.
I also tried,

system("export LD_LIBRARY_PATH;$java -cp $ENV{CLASSPATH} JavaClass");

You aren't actually setting LD_LIBRARY_PATH here, so I wouldn't expect
that to have any effect.

hp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top