Setting LD_LIBRARY_PATH env variable for child process

Discussion in 'Perl Misc' started by Lax, Apr 6, 2007.

  1. Lax

    Lax Guest

    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
    Lax, Apr 6, 2007
    #1
    1. Advertising

  2. Lax

    Big and Blue Guest

    Lax wrote:
    >
    > 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).

    > http://tinyurl.com/333h64


    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.

    --
    Just because I've written it doesn't mean that
    either you or I have to believe it.
    Big and Blue, Apr 6, 2007
    #2
    1. Advertising

  3. On 2007-04-06 19:48, Lax <> wrote:
    > 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


    --
    _ | Peter J. Holzer | I know I'd be respectful of a pirate
    |_|_) | Sysadmin WSR | with an emu on his shoulder.
    | | | |
    __/ | http://www.hjp.at/ | -- Sam in "Freefall"
    Peter J. Holzer, Apr 14, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Naresh Agarwal
    Replies:
    0
    Views:
    816
    Naresh Agarwal
    Jun 30, 2005
  2. Spitfire
    Replies:
    2
    Views:
    15,883
    Thomas Fritsch
    Feb 15, 2007
  3. TDR
    Replies:
    3
    Views:
    162
    Daniel Berger
    Aug 31, 2007
  4. Moritz Karbach

    Problem with setting LD_LIBRARY_PATH

    Moritz Karbach, Apr 21, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    192
    Moritz Karbach
    Apr 21, 2005
  5. Z W
    Replies:
    0
    Views:
    162
Loading...

Share This Page